Importing a list of items into multiple drop down box fields with different names

New Here ,
Aug 31, 2018 Aug 31, 2018

Copy link to clipboard

Copied

Hi,

I am trying to shorten the script below which allows me to import the same list of items into multiple drop down box fields.  I would like to be able to list the fields in a row using a single command instead of executing the complete command for each field.  The script does work but I would like to streamline as it populates a large number of fields.

var aOptions = [
    "One",
    "Two",
    "Three"
];

this.getField("Parts 1").setItems(aOptions);this.getField("Parts 2").setItems(aOptions);this.getField("Parts 3").setItems(aOptions);

TOPICS
Acrobat SDK and JavaScript, Windows

Views

162

Likes

translate

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

correct answers 1 Correct Answer

Most Valuable Participant , Sep 01, 2018 Sep 01, 2018
You can do it using an array, like this:var aOptions = [ "One", "Two", "Three" ];var fields = ["Parts 1", "Parts 2"];for (var i in fields) this.getField(fields).setItems(aOptions);

Likes

translate

Translate

Translate
Most Valuable Participant ,
Sep 01, 2018 Sep 01, 2018

Copy link to clipboard

Copied

You can do it using an array, like this:

var aOptions = [ "One", "Two", "Three" ];

var fields = ["Parts 1", "Parts 2"];

for (var i in fields) this.getField(fields).setItems(aOptions);

Likes

translate

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
New Here ,
Sep 01, 2018 Sep 01, 2018

Copy link to clipboard

Copied

Thanks for the prompt response, the script worked fantastically!

I put together an excel spreadsheet which combines a parts description and 2 part numbers into a single column and also auto inserts the script quotation marks and commas for each item making scripting a lot easier in the future.

For anyone interested the following formula in excel allows you combine 3 columns in excel into a single column and also automatically inserts the required javascript quotation marks and commas.  The additional / between columns is to separate the description and part numbers in the drop down box text.  In this example the formula is applied to column D in the excel spreadsheet which is the combined column I cut and paste into the document level javascript.

=CONCATENATE("""",A2," / ",B2," / ",C2,""",")

Likes

translate

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 ,
Sep 01, 2018 Sep 01, 2018

Copy link to clipboard

Copied

There is a concatenate method for the String object that can perform the Excel macro CONCATENATE action.

event.value = "".concat('"', this.getField("A2").value, " / ", this.getField("B2").value, " / ", this.getField("C2").value, "\",")

One could also create a "smart" concatenate function the only applies the separator character when the input values are not null strings.

Likes

translate

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