Skip to main content
Inspiring
February 8, 2022
Question

Want to map table data from a pulldown menu to various places in a document

  • February 8, 2022
  • 1 reply
  • 11223 views

I’m updating a form used for booking truck rentals. I’ve come up with a plan for the interactive elements. I have a couple holes in my knowledge and would like to ask for for some advice to help me complete it. 

 

Here’s the situation. The client would like to have it where up to 30 trucks can be listed on the form, and each of the 30 trucks could be one of seven different models. The idea is to choose from a pull-down menu for each truck which has “NO TRUCK” as the default choice with the seven models as options. Once a model is chosen, there are eight data sets associated with each model that would be mapped to the truck rental number. That truck rental number’s data results will show up in various places in the forms.

 

The truck rentals are given names T01, T02, T03, etc… so their data sets are given a suffix in their fields like this…

 

T01d - Truck 1 depreciation value

T01v - Truck 1 original value

T01w - Truck 1 weekly fixed charge

… and so on for eight different sets.

 

The truck models have their data sets listed like this….

TD1d - (first model) depreciation value

TD2d - (second model) depreciation value

TD2v - (second model) original value

… and so on for all the models and all the data sets. 

 

I want to be able for the appropriate model TD data sets to get mapped to the T01 to T30 data sets when the user uses the drop-down menu and picks a model.

 

And it seems to me that by using a document level script I could save a lot of hassle in editing. Someone here recommended that I should think that way for a future project and I haven’t forgotten. So I’m anticipating doing that and here’s how I thought it out…

 

My plan is that each dropdown menu would be fields labeled T01t, T02t, etc. Would it be possible to write a document level script that can:

- grab the first three characters of the current rental dropdown menu field name (ex.: T01) as a variable

- grab the first three characters of the chosen truck model field name (ex.: TD3) as a variable

- use those variables to join with a chosen fourth character to know which data sets to find

- map those data sets together and display them in the appropriate fields in the forms

 

My thought is that would allow a single document level script to do all the work of combining rentals with trucks and their data in various places on the form. Rental 1 would pick Truck model 3, and the script would know to grab Truck model 3’s data and map them to Rental 1’s spots on the various forms.

 

I’ve split path parts before and joined, but I’m not finding how to grab character parts here. I seem to see FieldName as something to work with. 

 

Lastly, am I overthinking this and is there a simpler way? I’ve done three projects with javascript in Acrobat so I’m taking what I know from the limited experience I have and attempting something much bigger. But some advice would certainly be welcome. Thank you.

This topic has been closed for replies.

1 reply

Thom Parker
Community Expert
Community Expert
February 8, 2022

Here are a couple of articles that describe a technique for maping selections to a data set. Both use a JavaScript object defined in a document script to hold the data, and a document script to define a generic function for mapping the data based on the field name of the drop down. 

 

https://acrobatusers.com/tutorials/change_another_field/

https://acrobatusers.com/tutorials/js_list_combo_livecycle/

 

The second one is for mapping selections dropdowns to a new set of items in another dropdown, but the technique is the same in both. A selection value in the dropdown selects a set of data in the JavaScript Object. 

You can read more about list and dropdown scripting here:

https://www.pdfscripting.com/public/List-Field-Usage-and-Handling.cfm

 

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Inspiring
February 8, 2022

Excellent, Thom. Thank you for sharing those. That's what I needed: some good resources.