If it is not already visible, display the Script Editor by selecting Palettes > Script Editor. Expand the Script Editor so that it is displayed in multiline view.
1.
Select the object on your form design that you want to add the script to and select an event from the Show list in the Script Editor. For example, choose the click event of a button or other interactive form object.
2.
Type one of the following scripts in the Script Editor, where Subform1 is the name of the subform to add instances to, and the value true indicates that the new subform instance should be merged with the form data:
Subform1.instanceManager.addInstance(true) // Default instance manager syntax
xfa.form.recalculate(true) // Invoke the recalculate method to include the field values from the added subform in the form calculations.
_Subform1.addInstance(true) // Short form of the instance manager syntax
xfa.form.recalculate(true) // Invoke the recalculate method to include the field values from the added subform in the form calculations.
Subform1.instanceManager.addInstance(true); // Default instance manager syntax
xfa.form.recalculate(true) // Invoke the recalculate method to include the field values from the added subform in the form calculations.
_Subform1.addInstance(true); // Short form of the instance manager syntax
xfa.form.recalculate(true) // Invoke the recalculate method to include the field values from the added subform in the form calculations.
2.
Type one of the following scripts in the Script Editor, where Subform1 is the name of the subform to remove an instance from and integer is the zero-based index number of the instance to remove:
Subform1.instanceManager.removeInstance(integer) // Default instance manager syntax
_Subform1.removeInstance(integer) // Short form of the instance manager syntax
Subform1.instanceManager.removeInstance(integer); // Default instance manager syntax
_Subform1.removeInstance(integer); // Short form of the instance manager syntax
See also 

To add and remove subform instances using scripting