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

Trouble With Drop Down Adobe Scripts - Help Please

Community Beginner ,
Apr 07, 2019 Apr 07, 2019

Copy link to clipboard

Copied

Is there a maximum amount of data you can have in a drop down box?

I have a list of 6 clients (I'm starting small just to test)

I have a name, DOB and address.

I am using a script to populate a drop down box which lists all names:

var textFields = ["Aname", "Bname", "Cname", "Dname", "Ename", "Fname"]; 

 

if (event.source!=null && textFields.indexOf(event.source.name)!=-1) { 

    var items = [""]; 

    for (var i in textFields) { 

        items.push(this.getField(textFields).valueAsString); 

    } 

    this.getField("Dropdown1").setItems(items); 

I have also created custom fields to add the name, DOB & address into one field. (AFull Details, BFull Details etc.)  I am then trying to use this field in a drop down.  It seems to work for 5 clients, but when I add the 6th, it doesn't refresh the drop down...

var textFields = ["AFull Details", "BFull Details", "CFull Details", "DFull Details", "EFull Details", "FFull Details"]; 

 

if (event.source!=null && textFields.indexOf(event.source.name)!=-1) { 

    var items = [""]; 

    for (var i in textFields) { 

        items.push(this.getField(textFields).valueAsString); 

    } 

    this.getField("Dropdown2").setItems(items); 

I have changed the formula many times requesting Aname, Bname up to F and it works fine.  I have changed 1 at a time to show AFull Details, Bname etc which again works fine up to 5, but when I change the last one to show all 6 full details, my drop down still contains earlier data, even though I change all 6 fields each time to Test1, Test2  then next time Test01,. Test02 etc.

I need a maximum of 20 eventually, but am stuck getting past 5...

Can anyone help please??

TOPICS
Acrobat SDK and JavaScript

Views

384

Translate

Translate

Report

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
LEGEND ,
Apr 07, 2019 Apr 07, 2019

Copy link to clipboard

Copied

There are tools that will add the list of the 50 U.S. states and abbreviations into a drop down.

Votes

Translate

Translate

Report

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 ,
Apr 07, 2019 Apr 07, 2019

Copy link to clipboard

Copied

I've put over a 1,000 items in a dropdown.

Are any errors reported in the Console Window when you run the script for 6 items?  Because the most likely issue is an error in the script.

Have you tried simply putting a list of 6 times into the dropdown?

this.getField("Dropdown2").setItems(["a","b","c","d","e","f","g"]);

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

Votes

Translate

Translate

Report

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 Beginner ,
Apr 08, 2019 Apr 08, 2019

Copy link to clipboard

Copied

Hi Thom, this just sets text a, b, c etc into my dropdown.  I want a, b, c to refer to existing fields in my document.

I can get the drop down working when it pulls through simple data from a name fields for example (name1, name2, name3 etc) but when I use a calculated field to combine name1, address1, date of birth1 and then try to use this new field Full1, Full2, Full3 etc it seems to fail.

Votes

Translate

Translate

Report

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 ,
Apr 08, 2019 Apr 08, 2019

Copy link to clipboard

Copied

So you are using a calculation script to run this code? Is this the calculation script on the DropDown?

And are any errors reported in the console? 

Please answer all the questions.

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

Votes

Translate

Translate

Report

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 Beginner ,
Apr 08, 2019 Apr 08, 2019

Copy link to clipboard

Copied

Apologies, I have put this code as a calculated script in a blank text box which then refers to the dropdown in question.  There are no errors reported, the script works up to a point.

The drop down is working when I just use the 'name' field, the drop down is populated with all 6 names.

I have changed the script one field at a time changing Name1  (I've tried to simplify all my fields, I now have Title1 to Title6, Name1 to Name6 and Address1 to 6.  I have also created new fields to merge all this data called Full1 (which displays Title1, Name1 and Address1)

When I change my formula to show Full1, Name2, Name3, Name4 up to 6, the dropdown correctly displays all the info for client 1 (Full1) and then only the names for the remaining 5 cases.

I then went one step further and changed my script to Full1, Full2, Name3, Name 4 etc and the result was correct.

For some reason, when I get to Full1, Full2, Full3, Full4, Name5, Name6 it all goes wrong and my drop down doesn't refresh when I change the data and doesn't refresh my dropdown.

I know it's nothing wrong with Full5 or Full6 as I have tried changing each one, one at a time and it works fine.  It's driving me crazy...  Could I email it to anyone to have a look for me?

Votes

Translate

Translate

Report

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 ,
Apr 08, 2019 Apr 08, 2019

Copy link to clipboard

Copied

Check the field calculation order.

Votes

Translate

Translate

Report

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 ,
Apr 08, 2019 Apr 08, 2019

Copy link to clipboard

Copied

Try running this script from the console window. That way you can validate the logic without the extra complication of event handling. I suspect that the calculation event is part of the issue.

Also, use console.println statements to show the flow of the script, i.e. add this line before setting the list items.

console.println("List:" + items);

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

Votes

Translate

Translate

Report

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 Beginner ,
Apr 08, 2019 Apr 08, 2019

Copy link to clipboard

Copied

LATEST

Thanks for the suggestions, I'll give it a go this evening and report back.

Cheers.

Votes

Translate

Translate

Report

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 ,
Apr 08, 2019 Apr 08, 2019

Copy link to clipboard

Copied

Try following code:

if (event.source!=null && textFields.indexOf(event.source.name)!=-1) {

    var items = [""];

    for (var i in textFields) {

        var f = this.getField(textFields);

        if (f != null)

          items.push(f.valueAsString);

        else {

            console.show();

            console.println("missing " + textFields);

          }

    }

    this.getField("Dropdown2").setItems(items);

}

Votes

Translate

Translate

Report

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 Beginner ,
Apr 08, 2019 Apr 08, 2019

Copy link to clipboard

Copied

Hi Bernd, thanks for your reply.  In your script, where do I put my field names please?

Votes

Translate

Translate

Report

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 ,
Apr 08, 2019 Apr 08, 2019

Copy link to clipboard

Copied

At the beginning add:

var textFields = ...

Votes

Translate

Translate

Report

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 Beginner ,
Apr 08, 2019 Apr 08, 2019

Copy link to clipboard

Copied

Sorry, I'm lost now, do you mean:

var textFields = "Full"

if (event.source!=null && textFields.indexOf(event.source.name)!=-1) {

    var items = [""];

    for (var i in textFields) {

        var f = this.getField(textFields);

        if (f != null)

          items.push(f.valueAsString);

        else {

            console.show();

            console.println("missing " + textFields);

          }

    }

    this.getField("Dropdown3").setItems(items);

}

Where Full is the name of the fields I want eg. Full1, Full2, Full3 etc.

Votes

Translate

Translate

Report

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 ,
Apr 08, 2019 Apr 08, 2019

Copy link to clipboard

Copied

I mean:

var textFields = ["AFull Details", "BFull Details", "CFull Details", "DFull Details", "EFull Details", "FFull Details"];

Votes

Translate

Translate

Report

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