Expand my Community achievements bar.

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

Copy all instances

Avatar

Level 3

Hello,

I would like to copy the data from a variable number of fields in a repeatable subform and paste them somewhere else.

How would I do this? I assume using the instance manager and maybe this.parent.index somehow...

Thank you for your time.

2 Replies

Avatar

Level 3

Still struggling with this but I have found some code that is making me think I am close.

My thought for the code below is to have click event

  • check the number if instances in a subform
  • create that exact amount of instances in another subform
  • copy the contents of the first subform instances into an array
  • paste the contents of this array in the new instances.

// on click vent

// create new empty array

var ofirstArray = [];

for (var i = 0; i < _nameSubform1.count; i++) // this is the total number of instances in nameSubform1 ...
{
  // get a reference to the nameSubform1[i] object
  var oSub1 = this.resolveNode("nameSubform1[" + i + "]");
  // set the value of its textfield object

  oSub1.textField.rawValue = ofirstArray[]; // fill this array with the contents of the instanced text field within nameSubform1
}

// now that we have the array filled paste the contents

// into a new subform with the same number of instances

_nameSubform2.setInstances(x); // x should be equal to _nameSubform1.count

for (var i = 0; i < _nameSubform2.count; i++) // this is the total number of instances in nameSubform2...
{
  // get a reference to the nameSubform2[i] object
  var oSub2 = this.resolveNode("nameSubform2[" + i + "]");
  // set the value of its textfield object

  oSub2.textField2.rawValue = ofirstArray[i]; // fill these text fields with the contents of the array created above from nameSubform1
}

I just confused myself there...I'm thinking now I can do it all in one for loop. I need help.

Avatar

Former Community Member

Your technique is right but you will have to copy each field in the subform to the other subform .....not just the subform nodes.

paul