Skip to main content
logistics227043683
Known Participant
February 12, 2019
Answered

How to use the, "set Items" function with a drop down box, and an Array?

  • February 12, 2019
  • 1 reply
  • 578 views

Good evening, I am attempting to use the "Set Items" function to add hundreds of words into a drop down box, using a for loop, and an Array.

I can use the same method of a loop to use the Array however I want, except for when it comes to adding the Array's contents into a drop down box.

Here is my code:

/*Here we will import, and read from a specific text file,

  and then assign the text file into an array, seperated by '\n' */

this.importDataObject("MED & DIAGNOSIS & ICD-10.txt", "C:/Users/dell/Documents/MED & DIAGNOSIS & ICD-10.txt");

var oFile = this.getDataObjectContents("MED & DIAGNOSIS & ICD-10.txt");

var cFile = util.stringFromStream(oFile, "utf-8");

var fileArray = cFile.split('\n');

/* Here, we will loop through the array equal to its length,

   attempting to add every other value in the array into a drop down box. 

   This portion of the code does not work, however.

   "console.println(MedAnalysis);" works just fine in the loop, for instance. */

var Drop = this.getField("Drop Test");

var index, i;

for (i = 0; i < fileArray.length; i++) {

Cartographer = fileArray.split('\t');

MedAnalysis = Cartographer[0]

Drop.setItems([MedAnalysis]);

}

Any help would be wonderful, thank you!

This topic has been closed for replies.
Correct answer try67

You need to use the setItems command once, outside the loop, on an array of items that contains just those values you want to apply.

So change this part:

for (i = 0; i < fileArray.length; i++) {

    Cartographer = fileArray.split('\t');

    MedAnalysis = Cartographer[0]

    Drop.setItems([MedAnalysis]);

}

To:

var items = [];

for (i = 0; i < fileArray.length; i++) {

    Cartographer = fileArray.split('\t');

    MedAnalysis = Cartographer[0];

    items.push(MedAnalysis);

}

Drop.setItems(items);

1 reply

try67
try67Correct answer
Community Expert
February 12, 2019

You need to use the setItems command once, outside the loop, on an array of items that contains just those values you want to apply.

So change this part:

for (i = 0; i < fileArray.length; i++) {

    Cartographer = fileArray.split('\t');

    MedAnalysis = Cartographer[0]

    Drop.setItems([MedAnalysis]);

}

To:

var items = [];

for (i = 0; i < fileArray.length; i++) {

    Cartographer = fileArray.split('\t');

    MedAnalysis = Cartographer[0];

    items.push(MedAnalysis);

}

Drop.setItems(items);