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

How to Get Item Value from Drop-down List

New Here ,
Feb 18, 2022 Feb 18, 2022

Hello All,

 

I have zero experience in Acrobat Form with multiple selections and foray into drop-down list. Referring to Mr. Thom Parker's article of "Programming list and combo fields in Acrobat and LiveCycle forms - Part 1 of 2", I have learned from you a lot. The example file "ListProgramming_Part1_AcroForm.pdf" is exactly what I need.

 

I tried to export into .csv file in Excel and would like to display "item value" in the spreadsheet as opposed to "export value" from Drop-down List "Part" . For this purpose, I have googled and acquired some basic knowledge from JavaScript for Acrobat API Reference.

 

Based on the example file, I added the codes below extra into "Example1" document JavaScript, which contains scripts created.

 

function expPartValue() {
    if(!event.willCommit){
    var cRowName = event.target.name.split(".").shift();
    var f = this.getField(cRowName + ".PartSelect");
    var a = f.currentValueIndices;
    console.println(f.getItemAt(a, false));
    }
}

 

In order to test, calling “expPartValue()” function from a the Keystroke Event of "PartSelect" field, the results are displayed in the console window of JavaScript Debugger. Regardless it may be ok with me.(For sure, it is flawed.)

 

Screenshot.jpgexpand image

 

When I replaced "console.println(f.getItemAt(a, false));" with
"event.value = f.getItemAt(a, false);", it does meet the expectation.

 

May I ask a question about how I can get item value. I am wondering whether the codes are wrong. Any advices from you are highly appreciated.

 

 

TOPICS
JavaScript , PDF forms
5.1K
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
1 ACCEPTED SOLUTION
Community Expert ,
Feb 19, 2022 Feb 19, 2022

So first, please keep you question simple and focused on a single topic. The more clear and concise the question, the better the answer. 

 

You should also read these articles:

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

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

 

Now, the keystroke and willCommit events are called when the field value is in transition. None of the actual field value properties have been changed. The "currentValueIndices" property contains the index for the current selection, not the selection just made by the user. Similarly, the "getItemAt()" function returns the item values for the current selection, not the one just made. The only way to get the new selection is through the event properties. 

 

Both of these properties, the change value and the new export, are provided through the proper Keystroke event, i.e. when "event.willCommit" is false

You can find this information by consulting the Acrobat JavaScript Reference:

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

 

Here's a modification of your scirpt  

 

function expPartValue() {
    if(!event.willCommit){
        console.println("Keystroke: Change=" + event.change + "  Export=" + event.changeEx);
    }
}

 

 

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

View solution in original post

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 19, 2022 Feb 19, 2022

So first, please keep you question simple and focused on a single topic. The more clear and concise the question, the better the answer. 

 

You should also read these articles:

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

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

 

Now, the keystroke and willCommit events are called when the field value is in transition. None of the actual field value properties have been changed. The "currentValueIndices" property contains the index for the current selection, not the selection just made by the user. Similarly, the "getItemAt()" function returns the item values for the current selection, not the one just made. The only way to get the new selection is through the event properties. 

 

Both of these properties, the change value and the new export, are provided through the proper Keystroke event, i.e. when "event.willCommit" is false

You can find this information by consulting the Acrobat JavaScript Reference:

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

 

Here's a modification of your scirpt  

 

function expPartValue() {
    if(!event.willCommit){
        console.println("Keystroke: Change=" + event.change + "  Export=" + event.changeEx);
    }
}

 

 

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
New Here ,
Feb 19, 2022 Feb 19, 2022
LATEST

That is great, Thom. Thanks a ton for your advices and help. 

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 19, 2022 Feb 19, 2022

Exporting to a CSV is a different issue. First, a script in Acrobat cannot write directly to an external file that is not a PDF.  A script can write to a PDF file attachment, but only in Acrobat Pro. The free reader is restricted.

But assuming that the user has Acrobat Pro, the best way to do this would be to add a button to the form labeled "Save to CSV", then write a button script to create the CSV file as an attachment. 

 

 

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