Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

Engaged ,
Feb 07, 2022 Feb 07, 2022

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.

TOPICS
PDF forms
11.9K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 18, 2022 Feb 18, 2022

All Correct.  

My text was a little sloppy in the previous post. I've corrected it. 

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Feb 19, 2022 Feb 19, 2022

All right, Thom. Gave it a go, and nothing is happening. I added both the SetupTruckData and the ChangeModelMenus scripts to the Document Scripts area. This should set up the data for the truck, plus create the list of model numbers for the combo box fields for each truck rental situation. I put a button under the Truck Data Table with just the function name activation for those two functions in case any data gets updated.

The first combo box for Truck rental #1 has a script added to the Actions to run the SetFieldValues function which would collect the info from oTruckData run during SetupTruckData and put it into all fields in the forms that are T01a, T01v, T01w, etc. But when I pick an truck model other than "NO TRUCK" (which has blank data in all the options so that the fields out there would stay blank), the choice is selected but no change in those fields throughout the form.

 

NOTE: I should note that I prepopulated the combo boxes when doing layouts in InDesign. So they already had the truck models in them, figuring they shouldn't be blank to start. Should I have them blank to start and let the scripts populate them?  I went to the TruckDataTable and changed a model name to see if running the "update" button would change all the combo box listings. They did not. So that isn't working. I can put all the scripts here that I added with notes included, and I'll attach my PDF so you can see it for real. I thought I was going to have this all completed, but something is amiss.

 

Helpful notes: There's a menu on the first page as to the items in question: See Entry Table (page 4 for the Truck 1 combo box with a script to execute SetFieldValues), Truck Data Table (page 7 - and the yellow button at the bottom is the update function scripts), Appendix 1 (pages 16-18, the first rows are where some of the fields would receive data after choosing the model number from Truck 1 Rental combo box). There are spots on page 36 that would receive data from the choices of the rental combo boxes, as well.

 

The scripts: 

 

// DOCUMENT LEVEL SCRIPTS ------

// START SetupTruckData function
     
function SetupTruckData(){
// make truck data a document level object
var  oIDFld, strNameBase, oTruckData = { };
for(var i=1;i<8;i++)
{
    strNameBase = "TD" + i ;
    oIDFld = this.getField(strNameBase  + "o");
    if(oIDFld.valueAsString != "")
        oTruckData[oIDFld.valueAsString] = 
                     { year: (this.getField(strNameBase +"y").value), 
                       options: (this.getField(strNameBase +"o").value), 
                       charge: (this.getField(strNameBase +"w").value), 
                       value: (this.getField(strNameBase +"v").value), 
                       depreciation: (this.getField(strNameBase +"d").value), 
                       weight: (this.getField(strNameBase +"x").value), 
                       cab: (this.getField(strNameBase +"c").value), 
                       fees: (this.getField(strNameBase +"f").value),
                       asset: (this.getField(strNameBase +"a").value),
                       residual: (this.getField(strNameBase +"r").value) }; 
}
}

// First call on document open to setup data
SetupTruckData(this);

// END SetupTruck Data function

// START ChangeModelMenus function

// PUTS THE LIST COMPILED FROM oModelChangeList VARIABLE INTO ALL COMBO BOXES IN GROUP "T" COMBO BOX LISTS TO COVER ALL 30 INSTANCES
function ChangeModelMenus() {
    if(event.willCommit) {
        var lst = oModelChangeList();
        this.getField("T").setItems(lst);
    }
}

// END ChangeModelMenus function

// START Variable oModelChangeList

// GRABS MODEL NAMES FROM COLUMN o IN TRUCK DATA TABLE
var oModelChangeList = [this.getField("TD1o").value,
    this.getField("TD2o").value,
    this.getField("TD3o").value,
    this.getField("TD4o").value,
    this.getField("TD5o").value,
    this.getField("TD6o").value,
    this.getField("TD7o").value,
    this.getField("TD8o").value];

// END Variable oModelChangeList

// First call on document open to setup data
ChangeModelMenus(this);


// END  DOCUMENT LEVEL SCRIPT ------

 


// START Button to go under Truck Data Table for Live Updating - updates truck data, and update combo boxes

//Make an "update" button, put this code into the MouseUp action of a button.
 
SetupTruckData(this);
ChangeModelMenus(this);
     
// END BUTTON



// COMBO BOX SCRIPT ------ edit row numbers in SetFieldValues event for each combo box by it's rental number

// START Keystroke Script for all Combo Boxes - Edit row numbers for each Truck Rental number - THIS FIRST SET ONLY HANDLES TRUCK RENTAL #1 (see third digit of the field names in the getField expressions)

if( event.willCommit )
{
     SetFieldValues(event.value);
}

// set the field values by grabbing data from SetupTruckData function
function SetFieldValues(cTruckModel)
{
  this.getField("T01y").value = oTruckData[cTruckModel].year;
  this.getField("T01o").value = oTruckData[cTruckModel].options;
  this.getField("T01w").value = oTruckData[cTruckModel].charge;
  this.getField("T01v").value = oTruckData[cTruckModel].value;
  this.getField("T01d").value = oTruckData[cTruckModel].depreciation;
  this.getField("T01x").value = oTruckData[cTruckModel].weight;
  this.getField("T01c").value = oTruckData[cTruckModel].cab;
  this.getField("T01f").value = oTruckData[cTruckModel].fees;
  this.getField("T01a").value = oTruckData[cTruckModel].asset;
  this.getField("T01r").value = oTruckData[cTruckModel].residual;
}

// END Kestroke script for Combo Boxes


// END COMBO BOX SCRIPT ------------------------

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 21, 2022 Feb 21, 2022

There are many different issues with the code on this form.  I think that you are trying to do too much in one go. There is a lot of code and some very basic scripting errors . This is a complicated form and so you really need to solve each issue one piece at a time, and you need to develop some debugging skills. 

Start by verifying the individual pieces, such as the "ChangeModelMenus" functionality.

Use the console window to do this. You'll find a free video on using the console here:

https://www.pdfscripting.com/public/Free_Videos.cfm#JSIntro

 

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Feb 21, 2022 Feb 21, 2022

Thank you, Thom for pointing me in that direction. I can see the logic in all the script examples you shared, so it made sense, but obviously some debugging is needed. I appreciate it.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Feb 21, 2022 Feb 21, 2022

-

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Feb 21, 2022 Feb 21, 2022

Thom, I have a question regarding setItems() which I learned from your ListProgramming_Part1_AcroForm.pdf example.

 

 

 

I see that you used a setItems(lst) to fill the combo box choices. So thought I would use the same. It looked I couldn't use the actual word "list" so I assume "lst" is safer. For my situation I'm getting an undefined message which doesn't make sense. Using the debugger on the following script, I checked the var oModelChangeList and did console.println on it and it printed all the model numbers in the array. Excellent.

 

Then I did var lst and the console.println came up "undefined".  That shouldn't be if var lst = oModelChangeList. Am I missing something about how you set up items to go to combo boxes? Well I thought I was learning something from your example.

 

Screen Shot 2022-02-21 at 7.54.08 PM.png

 

Also, I realize I don't think I set up properly my means to put all the truck models in the 30 combo boxes. I labelled the combo boxes as "T.01", "T.02", "T.03"... all the way up to to "T.30" anticipating that I'd figure out the way to get the setItems(lst) to get everything in Group T fields, but now I think I didn't get my fields labelled right. Your video talked about being able to apply mass changes across a group of fields, but I haven't been able to locate anything other than the idea I can apply toward a part of a field name like a group, based on something else I saw. How do you assign to a whole group of fields so that all 30 combo boxes get updated but they have to retain their own identity? They need their own identity because each one will run a script to populate certain fields based on the rental number.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 22, 2022 Feb 22, 2022

Excellent choice for a starting point!  You see the need to learn about JavaScript language basics. I'd stronly suggest following the tutorials at W3 Schools.

https://www.w3schools.com/js/default.asp

 

But to the immediate point:

Here's an array variable declaration

var aLst = [1,"a"];

You access the element of the list with indexes like this

 

aLst[0]; // returns 1

aLst[1]; // returns "a"

 

So what does aLst() do?  It doesn't do anything because aLst is not a function. Parenthese are the syntax for calling a function, which aLst is not. In fact, Acrobat should have thrown an exception on that line of code. 

 

Just call 

...setItems(oModeChangeList);

 

The input to the "setItems" function is an array. 

Of course this needs to be done on the individual fields, not the field group.

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Feb 22, 2022 Feb 22, 2022

It dawned on me last evening that instead of using lst, I should go directly to oModelChangeList without the lst handling the data. So you confirmed what I perceived. So instead of this:

function ChangeModelMenus() {
    if(event.willCommit) {
        var lst = oModelChangeList();
        this.getField("T").setItems(lst);
    }
}

... it really should be

function ChangeModelMenus() {
    if(event.willCommit) {
        this.getField("T").setItems(oModelChangeList);
    }
}

 

I obviously need more Javascript basics, unfortunately. Thanks for the tip. I like w3schools and use it a ton for CSS references.

 

Regarding my question about sending the setItems to the fields that all start with "T", could you point me to a reference to help me understand how to apply that oModelChangeList to each of the combo boxes with field names of "T.01", "T.02", "T.03"? Your video on field names said that field properties can have names with dot notation but a group of fields can be edited using the parts of the dot notation. I haven't been able to find a reference for that. 

 

Thank you for your help as I don't do Javascript very often, but wish I had started learning a while ago.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 22, 2022 Feb 22, 2022

It is not explained anywhere what properties can be set as a group.  But generally it's the widget properties and some value related props/functions, like reset, where there is commonality between the different field types. The "setItems" function is speicific to a particular field type, so it's not surprising it doesn't work for field groups. But none of this is really explained in the official Acrobat documentation. 

 

 The shortcut to setting every field in a group is to use an array iteration function.

Like this:

this.getField("T").getArray().forEach(function(a){a.setItems(oModelChangeList)});

 

  

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Feb 22, 2022 Feb 22, 2022

Oh wow, so that's a high-level trick since it's not in the documentation. So if I perceive it correctly, the forEach loops all the "T" fields but deals with them as a common object by using only the first part of the field name? The "a" refers to the first part of the field name? 

 

Aparently I'm trying something really intricate here. LOL

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 22, 2022 Feb 22, 2022

The forEach function  doesn't have anything to do with Acrobat scripting.  It's a Core JavaScript function for looping over arrays.  

Watch the two top videos here:

https://www.pdfscripting.com/public/Free_Videos.cfm#JSIntro

 

For things specific to the Acrobat JavaScript Model, see the Acrobat JavaScript Reference. 

for exmple, the getArray() function is a member of the Field Object:

https://opensource.adobe.com/dc-acrobat-sdk-docs/acrobatsdk/html2015/index.html#t=Acro12_MasterBook%...

 

 

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Feb 23, 2022 Feb 23, 2022

I gave your code a try as a Document Script since I could see that oModelChangeList did grab the truck models as an array. I edited one of the truck models and verified the console again to make sure it was grabbing the info...

 

Screen Shot 2022-02-23 at 10.54.50 PM.png

 

I clicked the button (in grey above, below the Truck Table. On MouseUp it runs ChangeModelMenus(this);

 

I went to the areas where the Truck rental fields are with combo boxes "T.01", "T.02", etc.... Here is field "T.01" opened up. The second truck model still shows the original 2022 model name and has not changed.

Screen Shot 2022-02-23 at 11.00.06 PM.png

 

This action is critical to my project. The client wants to be able to edit the truck models available for rent for all 30 rental slots.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 23, 2022 Feb 23, 2022

So, you have several issues with this particular piece of functionality.

As the script is currently written, the "ChangeModelMenus()" function was designed to operate in a keystroke script. If it is to be used in a MouseUp script the "event.willCommit" line needs to be removed because it is blocking the comboboxes from being updated.  This issue would have become immediately apparent with some "console.printlin" statements placed in the code.

Next,  the "ChangeModelMenus()" function does not update the "oModelChangeList" array. Since this is important, I would suggest moving the code that builds the oModelChangeList to inside the "ChangeModelMenus()" function. The ordering of operations is important and part of the debuging tasks is to ensure that correct actions are performed, and performed in the correct order. 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Feb 24, 2022 Feb 24, 2022

Thank you for pointing that out, Thom. I redid the ChangeModelMenus function to this...

Screen Shot 2022-02-24 at 7.57.05 AM.png

 

And lookie there.... the edited menu appears and it shows up in all the combo boxes. Excellent. 

Screen Shot 2022-02-24 at 7.57.32 AM.png

Part of the problem was that I didn't figure out how I could put a console.println statement in there because I wasn't sure what to put in the variable, but now fresh this morning, I see I didn't think of maybe it was the function name?

 

Okay, on to the function that populates the fields...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Feb 24, 2022 Feb 24, 2022

I went and added the SetupTruckData function to the Document Scripts....

function SetupTruckData()
{
var  oIDFld, strNameBase, oTruckData = { };
for(var i=1;i<8;i++)
{
    strNameBase = "TD" + i ;
    oIDFld = this.getField(strNameBase  + "o");
    if(oIDFld.valueAsString != "")
        oTruckData[oIDFld.valueAsString] = 
                     { year: (this.getField(strNameBase +"y").value), 
                       options: (this.getField(strNameBase +"o").value), 
                       charge: (this.getField(strNameBase +"w").value), 
                       value: (this.getField(strNameBase +"v").value), 
                       depreciation: (this.getField(strNameBase +"d").value), 
                       weight: (this.getField(strNameBase +"x").value), 
                       cab: (this.getField(strNameBase +"c").value), 
                       fees: (this.getField(strNameBase +"f").value),
                       asset: (this.getField(strNameBase +"a").value),
                       residual: (this.getField(strNameBase +"r").value) }; 
}
}
SetupTruckData(this);

 

... and I added the SetupTruckData(this); function to the button under the Data Table.

 

Next is to add the script to the first combo box. I read your tutorial examples on List Field Usage and Handling, and redid my script for the SetFieldValues so that I'm using commitOnSelChange and I assume this needed to be under the Format > Custom Keystroke Script section in the Field Properties for field "T.01". Since each truck rental need to populate specific fields, I'll have to edit this script in each combo box to reflect that rental number.

 

if( event.commitOnSelChange )
{
     SetFieldValues(event.value);
}

// set the field values by grabbing data from SetupTruckData function
function SetFieldValues(cTruckModel)
{
  this.getField("T01y").value = oTruckData[cTruckModel].year;
  this.getField("T01o").value = oTruckData[cTruckModel].options;
  this.getField("T01w").value = oTruckData[cTruckModel].charge;
  this.getField("T01v").value = oTruckData[cTruckModel].value;
  this.getField("T01d").value = oTruckData[cTruckModel].depreciation;
  this.getField("T01x").value = oTruckData[cTruckModel].weight;
  this.getField("T01c").value = oTruckData[cTruckModel].cab;
  this.getField("T01f").value = oTruckData[cTruckModel].fees;
  this.getField("T01a").value = oTruckData[cTruckModel].asset;
  this.getField("T01r").value = oTruckData[cTruckModel].residual;
}

  

This didn't populate any of of the "T01" group fields when implemented and choosing a truck model. I feel I'm missing something in the implementation. I must be real close, though, I think.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 24, 2022 Feb 24, 2022

Ok, so onto the next section of the form. And the next lesson. All variables have a characteristic called Scope. A variable's scope determines where it can be seen. A variable with function scope, can only be seen inside the function where it is declared. Declaring a variable in a function, means that variable only exists in that function.  A variable with document scope can be seen and used by any script in the document.  Variables are given document scope by declaring them in a document script, or attaching them to the document object. 

 

The "oTruckData" vaiable needs to be at the document level so that it can be setup and seen by all scripts in the document. Right now, the function that sets it up, gives it function scope. 

 

 

 

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Feb 24, 2022 Feb 24, 2022

I see, so scope is "visibility" of items so that parts of the document can see it or not. Right way I think of moving that variable outside of the SetupTruckData function in order to get it out in the open.

 

I looked up Scope on W3schools, and see there is a Block Scope when items are placed within curly braces.

 

 

var  oIDFld, strNameBase, oTruckData = { };

 

 

I see you wrote the var line of the three variables as "= { }", could you explain what that means? Is that saying these variables are blank or that they are "block"? (I did read the variables section on W3Schools to about declaration of multiple variables with commas was for a specific reason, since I'm trying to look for answers myself.) 

 

So I changed SetupTruckData to now be this:

 

 

var  oIDFld, strNameBase, oTruckData = { };

function SetupTruckData()
{
for(var i=1;i<8;i++)
{
    strNameBase = "TD" + i ;
    oIDFld = this.getField(strNameBase  + "o");
    if(oIDFld.valueAsString != "")
        oTruckData[oIDFld.valueAsString] = 
                     { year: (this.getField(strNameBase +"y").value), 
                       options: (this.getField(strNameBase +"o").value), 
                       charge: (this.getField(strNameBase +"w").value), 
                       value: (this.getField(strNameBase +"v").value), 
                       depreciation: (this.getField(strNameBase +"d").value), 
                       weight: (this.getField(strNameBase +"x").value), 
                       cab: (this.getField(strNameBase +"c").value), 
                       fees: (this.getField(strNameBase +"f").value),
                       asset: (this.getField(strNameBase +"a").value),
                       residual: (this.getField(strNameBase +"r").value) }; 
}
}
SetupTruckData(this);

 

 

But isn't that breaking apart the function? This didn't change the results of my combo box selection in the various fields out there.

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 24, 2022 Feb 24, 2022

There are two completetly different meanings for the curly brackets in JavaScript. The first is code block delimiters. The second is object literal notation. 

This line:

var a = {}; 

 

declares a varible named "a" that is initialized to an empty object. 

Here's a non-empty object literal

 

var a = {item1:1, item2:"b"};

 

However, what you really need to do is some debug on your code.  Where is this code being defined, excuted?  It should be in a document level script.  You could also be explicit about the reference to the oTruckData variable. Like this:

 

   

// This is assumed to be a document level script
// 
var oTruckData = { }; // This variable is document level

function SetupTruckData(oDoc)
{
    var  oIDFld, strNameBase; // These variables are local to the function
    for(var i=1;i<8;i++)
    {
       strNameBase = "TD" + i ;
       oIDFld = oDoc.getField(strNameBase  + "o");
       if(oIDFld.valueAsString != "")
          oDoc.oTruckData[oIDFld.valueAsString] = 
                     { year: (oDoc.getField(strNameBase +"y").value), 
                       options: (oDoc.getField(strNameBase +"o").value), 
                       charge: (oDoc.getField(strNameBase +"w").value), 
                       value: (oDoc.getField(strNameBase +"v").value), 
                       depreciation: (oDoc.getField(strNameBase +"d").value), 
                       weight: (oDoc.getField(strNameBase +"x").value), 
                       cab: (oDoc.getField(strNameBase +"c").value), 
                       fees: (oDoc.getField(strNameBase +"f").value),
                       asset: (oDoc.getField(strNameBase +"a").value),
                       residual: (oDoc.getField(strNameBase +"r").value) }; 
    }
}

SetupTruckData(this);

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Feb 24, 2022 Feb 24, 2022

Great. Thank you. So { } is "empty" for starters.

 

This script IS in the document level, by the way.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Feb 24, 2022 Feb 24, 2022

And I'm spending time in the W3Schools tutorials to fill in some holes.

 

Okay, debugging moves along.  I put the SetTruckData code in the debugger and ran a console.println on oTruckData since that's a variable that's going to be used in the combo boxes to SetFieldValues of the fields for each rental. The results came back as [object Object] and true. I assume that means that objects are found, but why two words and in different cases?

Here is the debugger output...

 

 

// This is assumed to be a document level script
// 
var oTruckData = { }; // This variable is document level

function SetupTruckData(oDoc)
{
    var  oIDFld, strNameBase; // These variables are local to the function
    for(var i=1;i<8;i++)
    {
       strNameBase = "TD" + i ;
       oIDFld = oDoc.getField(strNameBase  + "o");
       if(oIDFld.valueAsString != "")
          oDoc.oTruckData[oIDFld.valueAsString] = 
                     { year: (oDoc.getField(strNameBase +"y").value), 
                       options: (oDoc.getField(strNameBase +"o").value), 
                       charge: (oDoc.getField(strNameBase +"w").value), 
                       value: (oDoc.getField(strNameBase +"v").value), 
                       depreciation: (oDoc.getField(strNameBase +"d").value), 
                       weight: (oDoc.getField(strNameBase +"x").value), 
                       cab: (oDoc.getField(strNameBase +"c").value), 
                       fees: (oDoc.getField(strNameBase +"f").value),
                       asset: (oDoc.getField(strNameBase +"a").value),
                       residual: (oDoc.getField(strNameBase +"r").value) }; 
    }
}

SetupTruckData(this);
console.println(oTruckData);[object Object]
true

 

 

 

I then ran the combo box script through the debugger, and on the third line instead of 

 

 

     SetFieldValues(event.value);

 

 

I put an actual value from one of the menu choices (I assume since this isn't using a combo box when being tested, and in order to test I'm assuming you can't test a choice from a combo box without actually choosing one), you can see I put (NO TRUCK) in there as one of the real event values. I ran the console.println on (cTruckModel) since that's the parameter the function is running on. See the result...

 

 

if(event.commitOnSelChange)
{
     SetFieldValues(NO TRUCK);
}

// set the field values by grabbing data from SetupTruckData function
function SetFieldValues(cTruckModel)
{
  this.getField("T01y").value = oTruckData[cTruckModel].year;
  this.getField("T01o").value = oTruckData[cTruckModel].options;
  this.getField("T01w").value = oTruckData[cTruckModel].charge;
  this.getField("T01v").value = oTruckData[cTruckModel].value;
  this.getField("T01d").value = oTruckData[cTruckModel].depreciation;
  this.getField("T01x").value = oTruckData[cTruckModel].weight;
  this.getField("T01c").value = oTruckData[cTruckModel].cab;
  this.getField("T01f").value = oTruckData[cTruckModel].fees;
  this.getField("T01a").value = oTruckData[cTruckModel].asset;
  this.getField("T01r").value = oTruckData[cTruckModel].residual;
}

console.println(cTruckModel);
SyntaxError: missing ) after argument list
3:Console:Exec
undefined

 

 

 

So it says there is a missing ) after argument list on line 3? I have the right number of parenthesis on that line. If it's referring to a connection with the SetFieldValues function, I do not see any missing parenthesis or curly braces in that group. So I don't know what is being referred to as a missing ).

 

The W3Schools page on JS Debugging is right, debugging is not easy. I'm not sure how I'm to test this functionality, so perhaps my desire to try "NO TRUCK" is not a valid way of checking. You can tell I'm trying to consider how this is to work. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 25, 2022 Feb 25, 2022

I'm assuming the last bit of code that has the error is being run from the console window?

Context is critical. You need to let us know where the code is being executed.

 

There are several issue here.

1. functions must be defined before they are used. In the code above the function is defined after it is called. 

2. There is no "event.commitOnSelChange" property.  You can't just make up new object properties. Always look in the Acrobat JavaScript Reference. 

3. And if there were it would not be valid for code run in the console window. 

4. The input to the "SetFieldValues" function is a string.  the text No Truck is parsed as two variables with no proper separation, hence the error, missing ) after argument list.  Because it thinks No Truck is an agument list. If you want to pass in a string value, then it has to be quoted. Read about using strings. 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Feb 25, 2022 Feb 25, 2022

Yes, that was from the console window, I should have clarified that.

1. I see that now. I was reading up on functions more on W3S and saw that.

2. "commitOnSelChange" was something I thought I was grasping from your site. Instead of mouseUp, I assumed a combo box was a list change with a selection. This seemed to make sense. Just trying to use your links from early on here.

Screen Shot 2022-02-25 at 1.12.17 PM.png

 

I'll have to start using the Javascript Reference, as noted by your byline. I'm learning. 

4. Okay, that was because I was not using a string. I see it. 

Grabbing the Javascript reference....

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 25, 2022 Feb 25, 2022

So "commitOnSelChange" is a property of the list/combbox field, not the event object.  This property is also an option on the field properties dialog. It has no use in any of the scripts you're working on.

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Feb 27, 2022 Feb 27, 2022

Good news. REAL progress on my own. I spent good time reading the Acrobat Reference this weekend and made great progress with proper coding this time. I successfully got data to go to the final fields I wanted. That's a huge accomplishment. But I cannot change the data in the final fields by choosing another truck model. A recap of the process...

 

...this Truck Data table has all the data for the 8 truck models... All items in row one are labeled above with their field names. Row two is TD2y, etc....

Screen Shot 2022-02-27 at 10.15.31 PM.png

 

The grey button is the update button with this script:

SetupTruckData(this);
ChangeModelMenus(this);

 

Truck Row 1 is the default choice in all 30 combo boxes. The user will have to actually pick a model from rows 2 to 8 in the combo boxes for each rental situation.

 

The SetupTruckData Document Level function sets up all 80 of those fields with the truck model name (and that name in column "o" is what gets put in the combo boxes for each truck rental situation - that's the ChangeModelMenus function we solved last week). Here is SetupTruckData with debugging data at the end verifying it works for "oTruckData"...

 

 

 

 

// This is assumed to be a document level script
// 
var oTruckData = { }; // This variable is document level

function SetupTruckData(oDoc)
{
    var  oIDFld, strNameBase; // These variables are local to the function
    for(var i=1;i<8;i++)
    {
       strNameBase = "TD" + i ;
       oIDFld = oDoc.getField(strNameBase  + "o");
       if(oIDFld.valueAsString != "")
          oDoc.oTruckData[oIDFld.valueAsString] = 
                     { year: (oDoc.getField(strNameBase +"y").value), 
                       options: (oDoc.getField(strNameBase +"o").value), 
                       charge: (oDoc.getField(strNameBase +"w").value), 
                       value: (oDoc.getField(strNameBase +"v").value), 
                       depreciation: (oDoc.getField(strNameBase +"d").value), 
                       weight: (oDoc.getField(strNameBase +"x").value), 
                       cab: (oDoc.getField(strNameBase +"c").value), 
                       fees: (oDoc.getField(strNameBase +"f").value),
                       asset: (oDoc.getField(strNameBase +"a").value),
                       residual: (oDoc.getField(strNameBase +"r").value) }; 
    }
}

SetupTruckData(this);
console.println(oTruckData);[object Object]
true

 

 

 

 

And next the new combo box script. This one is in the first combo box for Truck Rental #1 only, and will only populate T01 group fields for the first truck rental. After adding this script, the fields listed in this script ("TO1y", "T01o", etc.) all displayed their values in Truck row 1 above in the Truck Data table! It works!

 

 

 

// set the field values by grabbing data from SetupTruckData function
if( event.willCommit )
function SetFieldValues(cTruckModel)
{    
  this.setFieldValue("T01y", oTruckData[cTruckModel].year);
  this.setFieldValue("T01o", oTruckData[cTruckModel].options);
  this.setFieldValue("T01w", oTruckData[cTruckModel].charge);
  this.setFieldValue("T01v", oTruckData[cTruckModel].value);
  this.setFieldValue("T01d", oTruckData[cTruckModel].depreciation);
  this.setFieldValue("T01x", oTruckData[cTruckModel].weight);
  this.setFieldValue("T01c", oTruckData[cTruckModel].cab);
  this.setFieldValue("T01f", oTruckData[cTruckModel].fees);
  this.setFieldValue("T01a", oTruckData[cTruckModel].asset);
  this.setFieldValue("T01r", oTruckData[cTruckModel].residual);
}
SetFieldValues(event.value);

 

 

 

 

But...the problem is when I use the combo box to change Truck Rental 1 from Truck model 1 to Truck model 2, there is no change in the T01- fields out there. The values from Truck Model 1 still stay. I saved the document and closed, reopened, and found Rental 1 was now at "NO TRUCK". It didn't save to the choice of the first actual truck model even though I had selected it and saved the doc.

 

And, editing the data table so that Truck 1's values are different is not changing the T01- fields, either. The original values are still there, and I have a button to update the data in the tables (just below the table). I know the scripts work, and the fields work because I have successfully put data in the final fields I want for Truck Rental 1. Yay! But now I need to know why changes are not setting. How do I troubleshoot this? A change in the combo box menu is not something that I'd be able to do in the debugger, or can I?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Feb 27, 2022 Feb 27, 2022

-

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines