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

Count and then display number of instances

NickiPT
Registered: May 24 2007
Posts: 12

I submitted this topic last week but it seesm to have disappeared from the site! I'll try again...
 
I have created a dynamic table that I named "Vehicle". It has one body row. In the body row, I created a subform with multiple text fields in it. Users will be entering information about their vehicles and I want to number their vehicles as they add more to the form. (There is an "Add Vehicle" button below the table.)

Here is my Hierachy:

Vehicle [Table]
Row1 [Body Row]
VehicleSubform [Subform]
VehicleNo [Text Field]
[Plus several other text fields within this subform]
AddVehicle [Button]

"VehicleNo" is the text field that should populate with a sequential number based on the number of instances of the subform. So for example, the field would populate with "1" if the user hasn't clicked on the "AddVehicle" button at all. Once they click "AddVehicle" for the first time, another instance of the subform will appear and I want the "VehicleNo" field on that subform to read "2". And so on.

The "AddVehicle" button is working perfectly; I just can't get the number of instances to appear in the "VehicleNo" text field.

I put _VehicleSubform.count in the calculate script for the "VehicleNo" text field. But that still shows "1" for each additional instance of the subform. I tried adding ++ at the end of the script but that didn't make any difference.

I am a scripting newbie, so I'm not sure which command(s) I need to make this happen. Any help would be greatly appreciated!
 

My Product Information:
LiveCycle Designer, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Use the "Initialize" event to set the count. Each instance of a subform has an index, you'd be better off using the index, rather than the count. try this code in the "initialize" event of the VehicleNo fields

this.rawValue = this.parent.index + 1;

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

NickiPT
Registered: May 24 2007
Posts: 12
That makes a "1" appear in the VehicleNo field, but when I press on the "Add Vehicle" button, the following subforms all also have "1" appearing in the VehicleNo field.
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
The trick is getting the hierarchy correct so that the code is referencing the correct subform. The one that is repeated.

I did an eSeminar on scripting instances in Dynamic LC forms on this site. There's also an example file
https://admin.adobe.acrobat.com/_a200985228/p87746471/

Alternatively, I've posted loads of videos and samples that cover exactly what you need at pdfscriping.com

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script