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 = [
this.getField("Parts 1").setItems(aOptions);this.getField("Parts 2").setItems(aOptions);this.getField("Parts 3").setItems(aOptions);
Copy link to clipboard
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);
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.
=CONCATENATE("""",A2," / ",B2," / ",C2,""",")
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.