0

I'm using Adobe Livecycle Designer ES4 to create some report. Based on XML a try to fill table. I have problem with Array. I push data into array in for loop. Below examples of my code:

  1. Results - blank textbox

    var print_data = xfa.record.containerPrintingData;
    var sfcArray = [];
    
    for (var i = 0; i < 10; i++) {
        sfc = print_data.resolveNode("sfcPrintingData["+ i +"]").sfc.value;    
        sfcArray.push(sfc);  
    };
    
    this.rawValue = sfcArray.toString();
  2. Results - get all items

    var print_data = xfa.record.containerPrintingData;
    var sfcArray = [];
    
    for (var i = 0; i < 10; i++) {
        sfc = print_data.resolveNode("sfcPrintingData["+ i +"]").sfc.value;    
        sfcArray.push(sfc);
        this.rawValue = sfcArray.toString();
    }
  3. Results - get 2nd item x 10

    var print_data = xfa.record.containerPrintingData;
    var sfcArray = [];
    
    for (var i = 0; i < 10; i++) {
        sfc = print_data.resolveNode("sfcPrintingData[1]").sfc.value;    
        sfcArray.push(sfc);
        this.rawValue = sfcArray.toString();
    }

Why 1st example don't work and 2nd work correct? I need use this array in another loops. How to solve it?

DirtyFrank
  • 59
  • 10
  • Does sfcPrintingData have exactly 10 items ? – sathish1409 Jun 04 '20 at 12:10
  • In this example XML have 2 items, but in some cases can be max 10. – DirtyFrank Jun 04 '20 at 12:14
  • This also wokrs: var print_data = xfa.record.containerPrintingData; var sfcArray = []; for (var i = 0; i < 10; i++) {     sfcArray.push(i); }; this.rawValue = sfcArray.toString(); – DirtyFrank Jun 04 '20 at 12:16
  • You should Exactly loop til the number of available items. If 2 items means, var print_data = xfa.record.containerPrintingData; var sfcArray = []; for (var i = 0; i < 2; i++) { sfcArray.push(i); }; this.rawValue = sfcArray.toString(); – sathish1409 Jun 04 '20 at 12:26
  • Try to identify the number items and use it in the loop – sathish1409 Jun 04 '20 at 12:27
  • I know that XML in this case have exactly two nodes. Question is why I can display all items in textbox when this.rawValue = sfcArray.toString(); is in the loop, but I can't display when this.rawValue = sfcArray.toString(); is outside the loop? – DirtyFrank Jun 04 '20 at 12:42

1 Answers1

1

Because, If it has 2 items, and you looping it for 10.

What happends is, when this.rawValue = sfcArray.toString(); is inside the loop, this.rawValue gets updated 2 times. First time One item will be there. second time 2 items. For the next iteration there is no 3rd item. So code breaks with error. But this.rawValue still have 2 items.

Where as, when this.rawValue = sfcArray.toString(); is outside the loop, the code breaks with error and this.rawValue don't have any items in it.

sathish1409
  • 245
  • 3
  • 6
  • Thanks for explanation. You have right. So, first I should count nodes (sfcPrintingData) and then do iteration (for loop), right? Just for sure ;) – DirtyFrank Jun 04 '20 at 12:55