Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn more

View all

Sign in to view all badges

copying nested table contents

martynd4832568
Level 2
Level 2

I need a little help here. I have an expanding table that has a nested (also expanding) table in it. The header row contains a user-entered project name. The nested table contains milestones for each project. I have a button used to move the completed project to an Archive page. Currently, I have the button executing 3 tasks:

1.     Add a new section to the Archive table

2.     Copy the contents of the Project table to the Archive table

3.     Delete the contents from the Projects table.

I can add a section to the Archive table, but it only copies the first line - the subsequent expanded lines are ignored.

I have been through the previous questions on this topic, but although similar, I cannot get them to work for me.

So, I need to add this:

1614769_pastedImage_1.png

to this

1614776_pastedImage_2.png

I have this code on the Click event of the green Archive button:

form1.Archive_Page.Table1.Row1.instanceManager.addInstance();

xfa.form.recalculate(true);

I have also included the hierarchy

1614777_pastedImage_3.png

Any help greatly appreciated by this newbie!  Using LC ES 4 on Windows 10.

6 Replies
MinusZero
Level 7
Level 7

Hi martynd4832568​,

You may need to copy each row with it's specific instance reference.

The first repeating row in the table with be specified with [0], second row [1], third row [2] and so on.

Assuming which is the repeating row. Copying the first row actionItem rawvalue would be something like this.

this.resolveNode("Archive_Page.Table1.Row1.SubForm2.Table2.Row1[0].actionItem").rawValue = this.resolveNode("Main.Table1.Row1.SubForm2.Table2.Row1[0].actionItem").rawValue;

For the second physical row instance you would use [1], third row [2] and so on.

I hope this gives you the start you needed. They can be a bit tricky.

martynd4832568
Level 2
Level 2

Thanks for the input - as you say, nested tables are tricky!

radzmar
Level 10
Level 10

If haven't had the time to build a nested table as yours but build a script from the hierarchy that should do the job.

var oRows = Table1.resolveNodes("Row1[*]"),

oSubRows,

oCopyTable = Archive_Page.Table1,

oCopyRows, oCopySubRows;

// Set same amount of rows in duplicated table

oTargetTable._Row1.setInstances(oRows.length);

oCopyRows = oCopyTable.resolveNodes("Row1[*]");

// Loop through source table rows

for (var i = 0; i < oRows.length; i += 1) {

     oSubRows = oRows.item(i).Subform2.Table2.resolveNodes("Row1[*]");

     // Set same amount of rows in nested table copy

     oCopyRows.item(i).Subform2.Table2._Row1.setInstances(oSubRows.length);

     oCopySubRows = oCopyRows.item(i).Subform2.Table2.resolveNodes("Row1[*]");

     // Loop through nested source table rows

     // Copy values from nested source to nested table copy

     for (var j = 0; j < oSubRows.length; j += 1) {

          oCopySubRows.item(j).actionItem.rawValue = oSubRows.item(j).actionItem.rawValue;

          oCopySubRows.item(j).Owner.rawValue = oSubRows.item(j).Owner.rawValue;

          // go on …

     }

}

martynd4832568
Level 2
Level 2

Many thanks for taking a look at this. As I said in my original post, I'm very much a newbie at this, so forgive a dumb question (or three!) - does this code REPLACE mine or is it in addition to it? I replaced it, but no joy. If it's in addition, where does it go?

I've just realized that I didn't post it. So here is my original work, broken down into the three steps:

form1.Main.Table1.Row1.Subform2.Table2.HeaderRow.Subform5.btn_Archive::click - (JavaScript, client)

// Step 1 - Add line to Archive page;

form1.Archive_Page.Table1.Row1.instanceManager.addInstance();

xfa.form.recalculate(true);

//Step 2 - Copy items to Archive Page

xfa.resolveNode("form1.Archive_Page.Table1.Row1.Subform2.Table2.HeaderRow[" + (form1.Archive_Page.Table1.Row1.Subform2.Table2.HeaderRow.instanceManager.count - 1) + "].Project_Desc").rawValue = xfa.resolveNode("form1.Main.Table1.Row1.Subform2.Table2.HeaderRow[" + this.parent.index + "].Project_Desc").rawValue;

xfa.resolveNode("form1.Archive_Page.Table1.Row1.Subform2.Table2.Row1[" + (form1.Archive_Page.Table1.Row1.Subform2.Table2.Row1.instanceManager.count - 1) + "].actionItem").rawValue = xfa.resolveNode("form1.Main.Table1.Row1.Subform2.Table2.Row1[" + this.parent.index + "].actionItem").rawValue;

xfa.resolveNode("form1.Archive_Page.Table1.Row1.Subform2.Table2.Row1[" + (form1.Archive_Page.Table1.Row1.Subform2.Table2.Row1.instanceManager.count - 1) + "].Owner").rawValue = xfa.resolveNode("form1.Main.Table1.Row1.Subform2.Table2.Row1[" + this.parent.index + "].Owner").rawValue;

xfa.resolveNode("form1.Archive_Page.Table1.Row1.Subform2.Table2.Row1[" + (form1.Archive_Page.Table1.Row1.Subform2.Table2.Row1.instanceManager.count - 1) + "].startDate").rawValue = xfa.resolveNode("form1.Main.Table1.Row1.Subform2.Table2.Row1[" + this.parent.index + "].startDate").rawValue;

xfa.resolveNode("form1.Archive_Page.Table1.Row1.Subform2.Table2.Row1[" + (form1.Archive_Page.Table1.Row1.Subform2.Table2.Row1.instanceManager.count - 1) + "].endDate").rawValue = xfa.resolveNode("form1.Main.Table1.Row1.Subform2.Table2.Row1[" + this.parent.index + "].endDate").rawValue;

xfa.resolveNode("form1.Archive_Page.Table1.Row1.Subform2.Table2.Row1[" + (form1.Archive_Page.Table1.Row1.Subform2.Table2.Row1.instanceManager.count - 1) + "].est_Hours").rawValue = xfa.resolveNode("form1.Main.Table1.Row1.Subform2.Table2.Row1[" + this.parent.index + "].est_Hours").rawValue;

//Step 3 - Removing copied items from first page  form1.Main.Table1.Row1.Subform2.Table2.Row1.actionItem     

//form1.form1.Main.Table1.Row1.Subform2.Table2.Row1.orderItem.instanceManager.removeInstance(this.parent.index); 

//xfa.form.recalculate(true);

Again, many thanks!

MinusZero
Level 7
Level 7

Hi,

radzmar​'s solution would replace your code.

If you dont want to go down the often confusing route of 'for statements', what you have would be placed in a button click. If you want to do multiple rows at the same time, you will have to write that code in as well. I have done that before. If your subform is limited to the amount of rows that can be added, you only have to write a finite amount of code.

martynd4832568
Level 2
Level 2

Hi Radzmar

I copied over the code you supplied into the click event of the button, but nothing happens. Any suggestions as to what I do now? Really appreciate your help on this.