Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

add new instance and copy data

Avatar

Former Community Member

 

Client requested following:

Each click of button creates a new instance of subform ( just 10 text fields), not the table.

They want another button, that will create a new instance of the subform and copy the data from the first instance, every time they click on the button.
Does anyone have a code in JavaScript to share?

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi,

You could probably do this as a loop through the objects in the subform, but given there is only ten, you could script each one in turn:

// Add the instance

page1._Subform.addInstance(true);

// Duplicate from first instance

var nCount = page1._Subform.count - 1;

var oFirst = xfa.resolveNode("page1.Subform[0]");

var oLast = xfa.resolveNode("page1.Subform[" + nCount + "]");

oLast.TextField1.rawValue = oFirst.TextField1.rawValue;

oLast.TextField2.rawValue = oFirst.TextField2.rawValue;

oLast.TextField3.rawValue = oFirst.TextField3.rawValue;

Something like this should work,

Niall

View solution in original post

3 Replies

Avatar

Correct answer by
Level 10

Hi,

You could probably do this as a loop through the objects in the subform, but given there is only ten, you could script each one in turn:

// Add the instance

page1._Subform.addInstance(true);

// Duplicate from first instance

var nCount = page1._Subform.count - 1;

var oFirst = xfa.resolveNode("page1.Subform[0]");

var oLast = xfa.resolveNode("page1.Subform[" + nCount + "]");

oLast.TextField1.rawValue = oFirst.TextField1.rawValue;

oLast.TextField2.rawValue = oFirst.TextField2.rawValue;

oLast.TextField3.rawValue = oFirst.TextField3.rawValue;

Something like this should work,

Niall

Avatar

Level 2

Niall,

What would the script be to duplicate from the previous instance instead of from the first instance? So if you have apples in the first instance, add a row and change to oranges, how would you make sure that the oranges row copied next?

Thanks!

Scott