This example demonstrates how to use the methods of the instance manager (which is part of the XML Form Object Model) to perform operations on subform objects at run time. For example, you can add remove instances of a particular subform, table, or table row.
In the following form, the form filler uses the four buttons to use the various instance manager scripting methods. For example, when the form filler clicks the Add button a new Subform2 instance is added to the form.
Livecycle common scripting tasks.106.14.1 Using the methods of the instance manager to control subforms
Note:
The Move button reorders the first two Subform2 instances, and the Set button displays the maximum number of Subform2 instances. In both cases, you may need to add or remove subforms, or make changes to the data in the text fields to see the changes applied to the Subform2 instances.
The following script determines whether the supported maximum number of Subform2 instances exist on the form. If the maximum number exists, the script displays a message. Otherwise, a new Subform2 instance is added to the form.
if (methods.Subform2.instanceManager.count ==
methods.Subform2.instanceManager.max) {
xfa.host.messageBox(“You have reached the maximum number of items allowed.”,
“Instance Manager Methods”, 1);
}
else {
methods.Subform2.instanceManager.addInstance(1);
xfa.form.recalculate(1);
}
if (methods._Subform2.count == methods._Subform1.max) {
xfa.host.messageBox(“You have reached the maximum number of items
allowed.”, “Instance Manager Methods”, 1);
}
else {
methods._Subform2.addInstance(1);
xfa.form.recalculate(1);
}
The following script determines whether any Subform2 instances exist on the form. If none exist, the script displays a message indicating that no instances exist. If instances do exist, the script removes the first instance from the form.
if (methods.Subform2.instanceManager.count == 0) {
xfa.host.messageBox(“There are no subform instances to remove.”,
“Instance Manager Methods”, 1);
}
else {
methods.Subform2.instanceManager.removeInstance(0);
xfa.form.recalculate(1);
}
if (methods._Subform2.count == 0) {
xfa.host.messageBox(“There are no subform instances to remove.”,
“Instance Manager Methods”, 1);
}
else {
methods._Subform2.removeInstance(0);
xfa.form.recalculate(1);
}
methods.Subform2.instanceManager.setInstances(4);
methods._Subform2.setInstances(4);
methods.Subform2.instanceManager.moveInstance(0,1);
methods._Subform2.moveInstance(0,1);

Using the methods of the instance manager to control subforms