Expand my Community achievements bar.

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

Copy text fields value to new instance.

Avatar

Level 2

I have a subform where I use "TAG.instanceManager.addInstance(1);" to create a new instance of the subfrom, but I also want to have a button that creates a new instance that copies the values of the current instance. (See Below Image, have also provided hierarchy if that helps)   Is there a way to have the values copy to the new instance?  Any help would be appreciated. Thanks

Example.png

Hierarchy.png

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi,

If you clone the data node the TAG subform is bound to before you do the addInstance(1) then the new form nodes will bind to the new data nodes.

So try this JavaScript in the click event of your CopyTagBtn

var tags = page1.resolveNodes("TAG[*]");

// Get the last TAG to clone

var tag = tags.item(tags.length - 1);          

// Create new data group to bind to

tag.parent.dataNode.nodes.append(tag.dataNode.clone(true));

// Add new TAG instance, which will bind to the new data group

TAG.instanceManager.addInstance(1);

Regards

Bruce

View solution in original post

6 Replies

Avatar

Correct answer by
Level 10

Hi,

If you clone the data node the TAG subform is bound to before you do the addInstance(1) then the new form nodes will bind to the new data nodes.

So try this JavaScript in the click event of your CopyTagBtn

var tags = page1.resolveNodes("TAG[*]");

// Get the last TAG to clone

var tag = tags.item(tags.length - 1);          

// Create new data group to bind to

tag.parent.dataNode.nodes.append(tag.dataNode.clone(true));

// Add new TAG instance, which will bind to the new data group

TAG.instanceManager.addInstance(1);

Regards

Bruce

Avatar

Level 2

Bruce,

That worked perfectly, thank you very much!

Regards

Chris

Avatar

Level 6

How would you get this to work to only copy select/desired fields with a subform, not the entire subform group content?

For instance, subForm A has First name, Last name, and Email and 3 other fields within the subform. The subform is set to repeat in binding tab. What I desire is that whatever info is entered in subform A fields (First name, last name, and email) gets carried over to Subform B automatically.  When a new instance of subform A is created (via an Add group button), the fields should be blank  data input. Howver, whatever is entered in the second instance would create a new instance in Subform B with the same data.

So again, there could be say 5 fields in subform A..I would just want first name, last name, and email to carry over to Subform B instances.

SO I guess we are not only creating new instances, but also duplicating select data within each instance. The data in each instance wil be different.

Shawn

Avatar

Level 10

Create one table to enter data freely and able to add instance, and each time you add an instance of a row in the first table, you also add a row in the second table.

When you enter data into the fields just create a script to put the data from one table to the other table

Ex: Table1.Row1.TextFieldName:exit event

          this.resolveNode("Table2.Row1[" + this.parent.index + "].TextFieldName").rawValue = this.rawValue;

     Table1.Row1.SubformAddDelete.ButtonAdd:click event

          this.parent.parent.instanceManager.addInstance(1);

          this.resolveNode("Table2.Row1").instanceManager.addInstance(1);

Something like that

Avatar

Level 6

PERFECT! Just what I was looking for... thanks alot Magus069!