Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

copy all textfields value form one instance to another

Avatar

Level 4

I have a dynamic form in which two table with add instance row

when i click a button all textfields value from table1 to table2 textfields

there are any short form of this button click script

xfa.resolveNode(Table1.Row3[1].Cell1").rawValue = xfa.resolveNode("Table2.Row3[1].Cell1").rawValue;

xfa.resolveNode(Table1.Row3[1].Cell2").rawValue = xfa.resolveNode("Table2.Row3[1].Cell2").rawValue;

xfa.resolveNode(Table1.Row3[1].Cell3").rawValue = xfa.resolveNode("Table2.Row3[1].Cell3").rawValue;

xfa.resolveNode(Table1.Row3[1].Cell4").rawValue = xfa.resolveNode("Table2.Row3[1].Cell4").rawValue;

.....................

7 Replies

Avatar

Level 10

You could try this code, which copies the data from the last row of Table1 to a new row in Table2

Table2.dataNode.nodes.append(Table1.Row3.all.item(Table1._Row3.count - 1).dataNode.clone(true));

Table2._Row3.addInstance()

This will copy all cells in the row across, by cloning the Table1 dataNode for the row before adding the instance, so when the addInstance() is called it picks up the added data

Avatar

Level 4

its not working when previous add instance value change.

any other solution

Avatar

Level 10

If you need to keep Table2 in sync with Table1 you can add some code in the calculate event of Table2, something like;

// 'touch' every cell in Table1 so we know if anything has changed

var nodes = Table1.resolveNodes("$..Row3[*].#field[*]")

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

  var n = nodes.item(i).rawValue;

}

// Empty Table2, then add rows as need

Table2._Row3.setInstances(0)

var nodes = Table1.resolveNodes("Row3[*]");

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

  Table2.dataNode.nodes.append(nodes.item(i).dataNode.clone(true));

  Table2._Row3.addInstance()

}

This way you don't need the button to copy the data across

You will have to allow Table2.Row3 to minimum number of repeats set to zero

Avatar

Level 4

thanks to response

but i have separate buttons for add instance and copy data

because it is optional to copy data from table 1 or manually enter data in table 2

Avatar

Level 10

So if they do click the copy data button, then from that point on you need to keep the data in the row in sync?  If they hadn't click the copy data button then you don't worry if the previous values changes?

If so how are you remembering if the button has been clicked or not.

Also, were about is the button, is it in the row of one or other of the tables?

Avatar

Level 4

i am very sorry to late reply

sir i have one table for present address and second table for permanent address

both are sometimes will be same and sometimes not

so  need a button to copy from present address to permanent address when click

in both table it it not necessaru to have same rows it will add and remove by instant manager

Avatar

Level 10

Maybe I misunderstood by what you meant by "its not working when previous add instance value change"

Can you give more detail around what is wrong with the original suggestion?