These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Count Subform Instances

beachbumbali11
Registered: Mar 5 2008
Posts: 74

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

My Product Information:
LiveCycle Designer, Windows
almitche
Expert
Registered: Apr 1 2008
Posts: 41
I would caution against using this approach. I don't think the results are repeatable for all cases.

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.
beachbumbali11
Registered: Mar 5 2008
Posts: 74
great thanks for the suggestion will definatly try it out i couldnt get it to work from your last post but in my case i just did it a dirty way of counting it once within the same hierarchy then setting the field to global and making it hidden then making another field with the same name in the location i needed it