Expand my Community achievements bar.

Duplicate a set of instances and make read-only?!?

Avatar

Level 2

Does anyone know how to duplicate a set of instances later in a form upon clicking a button? (client wants a report page at the end)

2 Replies

Avatar

Level 2

Came up with my own solution... For anyone searching for a solution to a similar problem: basically I just created a new set of instances and copied them in.  See below:

//get total number of instances

var tasksNum = Page3._sfTasks.count;

var taskCount = 0;

//create report instances

Page4.sfTasks._sfTask.setInstances(tasksNum);

//loop through to populate corresponding data

for (i=0; i<tasksNum; i++)

{

          xfa.resolveNode("Page4.sfTasks.sfTask["+i+"]").taskID.rawValue = xfa.resolveNode("Page3.sfTasks["+i+"]").taskID.rawValue;

          xfa.resolveNode("Page4.sfTasks.sfTask["+i+"]").taskName.rawValue = xfa.resolveNode("Page3.sfTasks["+i+"]").taskName.rawValue;

          xfa.resolveNode("Page4.sfTasks.sfTask["+i+"]").comments.rawValue = xfa.resolveNode("Page3.sfTasks["+i+"]").inspectorComments.rawValue;

          taskCount ++;

}

Avatar

Level 8

I made a similar function to do just that. As long as the source set of subforms are named the same as the target, everything should transfer with ease. And it's reusable!

/************

*Build a target set of subforms

*based on a source making sure

*all objects are in the same order

*with same names

@para - source is the instanceManager object of the source set of subforms

@para - target is the instanceManager object of the target set of subforms(must be same name as source)

****************/

function loadData(source,target){

target.setInstances(source.count);//set the target's subform instances to match the source's

for (var a=0;a<source.count;a++){//loop through each subform instance

  var sourceSubform=source.resolveNode(source.name.substr(1)).all.item(a);

  var targetSubform=target.resolveNode(target.name.substr(1)).all.item(a);

  for (var b=0;b<sourceSubform.nodes.length;b++){//loop through the children of each

   if (sourceSubform.nodes.item(b).className=="field" && targetSubform.resolveNode(sourceSubform.nodes.item(b).name)!=null)//check for matching fields

    if (typeof(targetSubform.resolveNode(sourceSubform.nodes.item(b).name).value.exData)=="undefined" ||

     typeof(targetSubform.resolveNode(sourceSubform.nodes.item(b).name).value.exData.body)=="undefined")

     targetSubform.resolveNode(sourceSubform.nodes.item(b).name).rawValue=sourceSubform.nodes.item(b).rawValue;

    else

     targetSubform.resolveNode(sourceSubform.nodes.item(b).name).value.exData.loadXML(sourceSubform.nodes.item(b).value.exData.saveXML(),1,1);

   if (sourceSubform.nodes.item(b).className=="instanceManager" && targetSubform.resolveNode(sourceSubform.nodes.item(b).name)!=null)//check for matching subforms

    loadData(sourceSubform.nodes.item(b),targetSubform.resolveNode(sourceSubform.nodes.item(b).name));

  }

}

}

Kyle