I had been banging my head against a wall to try and count how many guests had been added to a expandable form using a addInstance command.
I finally finally got it figured out and it was simpler than I thought any one else who is looking for a simple way to count the number of rows or items or subforms added using the addInstance button heres how i did it.
Numeric field Formcalc Caculate
if(exists(yourSubform[0].anyField) == 1)
then
Count(yourSubform[*].anyField)
endif
the mind bender is that the field doesn't change names the subform itself if the item changing and the field names all stay the same whew glad i got that figured out
If you want to get the number of instances of a subform that appear on your form, you should use the count property. For example, consider this hierarchy:
Subform1
Button1
Button2
NumericField1
Subform2
[some objects]
Imagine Button1 and Button2 are add and remove buttons that add and remove instances of Subform2. NumericField1 is a field that displays the number of instances of Subform2.
To get the count of Subform2, I can use the following:
Subform2.instanceManager.count // FormCalc
Subform2.instanceManager.count; // JavaScript
I personally would put that in the calculate event of the NumericField1 object because the calculate event occurs whenever a change is made to the form, so the value should always update when Subform2 instances are added or removed.
Note: If I moved the NumericField1 field outside of Subform1:
NumericField1
Subform1
Button1
Button2
Subform2
[some objects]
my scripts would change slightly:
Subform1.Subform2.instanceManager.count // FormCalc
Subform1.Subform2.instanceManager.count; // JavaScript
But the event I'd put it on doesn't change.
Hope that helps.