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

Sorry if this has been answered or has some obvious answer that has avoided me but i have been searching and havent found the answer

Simply
subform with added instances in the heading section just want to know how many subforms they added

subform guests allows user to add guest info all i want is a box that shows the total number of guests.

Should i be trying to count the subform or would it be easier to count the number of a single text field in the subform?

Like i said there has to be a simple answer using formcalc but it has been avioding me

Any ideas greatly appreciated

almitche
Expert
Registered: Apr 1 2008
Posts: 41
hey beachbumbali11,

You could take a look at this Help topic: Scripting > Scripting Using LiveCycle Designer ES > Examples of Common Scripting Tasks > Using the properties of the instance manager to control subformsSpcifically the count property of subforms is what you need to use to get the count of repeated subforms.

Let me know if that doesn't help. We used to have samples showing how to do this on the Adobe Developer Center (www.adobe.com/devnet/livecycle) but typically I can't find them at the moment.

- Alex
beachbumbali11
Registered: Mar 5 2008
Posts: 74
well still looking for the count property of the subform the link is dead any other help you could offer would be most appreciated
almitche
Expert
Registered: Apr 1 2008
Posts: 41
Hey beachbumbali11,

Weird that the link didn't work. Perhaps the page was down? www.adobe.com/devnet/livecycle is a major dev portal for us.

Did the Help topic I mentioned work at all? The syntax I used (Scripting > Scripting Using LiveCycle Designer ES > Examples of Common Scripting Tasks > Using the properties of the instance manager to control subforms) is meant to show how to navigate through the Designer Help list of books and topics. You have to launch the Help inside Designer before you can start following the syntax though (I'm not sure if that is the broken link you mentioned).In the Help there is another topic that is adapted from a sample we created a few versions ago: Scripting > Scripting Using LiveCycle Designer ES > Examples of Common Scripting Tasks > Using the instance manager to control subforms at run time.Generally, you can obtain the number of instances of a subform using the count property. So:

Subform1.instanceManager.count // gets you the value
xfa.host.messageBox(Subform1.instanceManager.count) // outputs it in a message box so you can see it

The trick on a form where you have buttons for adding and removing instances of a subform is to account for the case where a user has removed all the instances (or conversely, has added a ton of instances). It's usually a good idea to set minimum and maximum values for your repeating subforms.

I hope that helps. Let me know if you need more and I'll try my best to give you more examples.

- Alex
beachbumbali11
Registered: Mar 5 2008
Posts: 74
Where is this help file here in acrobatusers.com on devcenter or the help in the menu of livecycle i cant seem to find this help tree also i am using designer 7 not es
sorry i must be incompetent tonight thanks for the help the script above is close

but i am missing something so i dont need the message box but its this
subform tree
guestInfo (flowed)
guestHead
GuestInfo (this is the expandable subform) min count of 1
right so i used the code above and am not getting anything
inside of guestHead numericfield total number of guests this number will be used latter but should be based on the number of GuestInfo subforms so
I followed your advise and put it in form1.guestInfo.numOfguest under javascript calculate

GuestInfo.instanceManager.count
xfa.host.messageBox(GuestInfo.instanceManager.count)

I get an error box with nothing in it and numOfguest is 1 but doesnt increase as the number of instances increases
can you please help me with this and tell we where the help files are
thanks kindly
almitche
Expert
Registered: Apr 1 2008
Posts: 41
hey again,

Just quickly ... the Help file is available from the Help menu in Designer. The most recent version is available online here:

www.adobe.com/go/learn_lc_designer

I will respond to the rest of your question as soon as possible.

- Alex
beachbumbali11
Registered: Mar 5 2008
Posts: 74
thank you for your quick reply you seem to be a pro for only being here for 6 days also all these links keep kicking me out like the page is being worked on or something I have tried opening it serveral times to no avail but great to know you understand my problem whenever you have time please try to lead me to a solution.
almitche
Expert
Registered: Apr 1 2008
Posts: 41
Sorry for the late reply.

I don't know about being a pro. I'm actually the writer responsible for some of the Designer scripting documentation, which means I know enough to be dangerous ;-)

Okay, here's some stuff to try. I'm giving you the scripts in FormCalc because that's originally what you asked about, but to convert any of them to JavaScript you just need to add a ";" (semi colon) to the end of each line).

Given your situation where you have a hierarchy that looks like this:

guestInfo
guestHead
GuestInfo
[object(s)]

I created a button outside of guestInfo (but it doesn't have to be). So my simplified hierarchy looks like this:

Button1
guestInfo
guestHead
GuestInfo
[object(s)]

I added the following script to the click event of Button1:

guestInfo.GuestInfo.instanceManager.addInstance()
guestInfo.guestHead.rawValue = guestInfo.GuestInfo.instanceManager.count

Basically it adds a new instance of GuestInfo, and then updates the value of the guestHead numeric field with the total number of GuestInfo instances that apppear on the form.

My GuestInfo subform (the one that repeats) has Min Count = 1, and Max = 5 (not that that matters too much, it's just what I have set).

So when the form first opens, guestHead displays a number equal to the Min Count value of the subform (GuestInfo), in my case = 1. Then each time I click the button to add a new GuestInfo instance, guestHead increases in value. Similarly, if I add a button to remove instances of GuestInfo, the value in guestHead decreases decrease.

I hope you follow that.

What I could have done is taken the second part of the script above and added it to the calculate event of guestHead (the numeric field):

guestInfo.guestHead.rawValue = guestInfo.GuestInfo.instanceManager.count

You have tried to do that, and I think that is the right way to go. I believe that is a more straightforward approach.

In this case, because it is on the calculate event, and because the relationship between where the script is and the object it references has simplified, I can reduce that line of script down to this:

GuestInfo.instanceManager.count

It's possible yours didn't work because you were missing the ";" (semi colon) on the end of each line of script (if you were using JavaScript). Your script looked good to me in it was running in FormCalc.

See if this works for you, and if not I'll see if we can get something else to work ;-)

Hope that helps.
beachbumbali11
Registered: Mar 5 2008
Posts: 74
Well mr almiteche your answer doesnt seem to be working i am using version 7 and in version 7 instance manager doesnt have a count property got a caculate but no count prroperty
so any other ideas would be greatly appreciated since i am such anovice here
almitche
Expert
Registered: Apr 1 2008
Posts: 41
Hmmm Acrobat 7 eh ... you are right, "count" wasn't introduced until Designer/Acrobat 8.0.

You could use the following FormCalc script instead:

GuestInfo.all.length

I put that in the calculate event of the field I wanted to display the number of subform instances, but obviously you can take that value and do whatever you want with it. As you can tell from the script, the field I was displaying the value is within your subform called "guestInfo" but exists outside of the subform "GuestInfo".

Try that and let me know how it goes.