Skip to main content
Participant
September 1, 2018
Answered

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

  • September 1, 2018
  • 1 reply
  • 1256 views

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);

This topic has been closed for replies.
Correct answer try67

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);

1 reply

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
September 1, 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);

Participant
September 1, 2018

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,""",")

Inspiring
September 1, 2018

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.