Skip to main content
Known Participant
October 14, 2020
Answered

Drop Down SetItems() resets the list

  • October 14, 2020
  • 1 reply
  • 784 views

Hi, everyone. I have a script in drop down field named "MODEL". It has two options is the list, G2500 and ONYX. Depending the selection, the script changes/sets the items of the list. When I try to select an item from the drop down list G1CDU other than first item, it goes back to the first item. So, I'm not able to select any other item.

this.getField("G1CDU").clearItems();
switch (event.value) {
case "G2500":
this.getField("G1CDU").setItems([
"Item 1",
"Item 2",
"Item 3"]);
break;

case "ONYX":
this.getField("G1CDU").setItems([
"Item 4",
"Item 5",
"Item 6"]);
break;

}

 Can you please help me in this regard?

This topic has been closed for replies.
Correct answer Nesa Nurani

Try using this code as custom validation script of MODEL field:

var seti = this.getField("G1CDU");

if (event.value == "G2500") {
seti.clearItems();
seti.insertItemAt("Item3");
seti.insertItemAt("Item2");
seti.insertItemAt("Item1");
} else if ( event.value == "ONYX"){
seti.clearItems();
seti.insertItemAt("Item6");
seti.insertItemAt("Item5");
seti.insertItemAt("Item4");
}

1 reply

Nesa Nurani
Community Expert
Nesa NuraniCommunity ExpertCorrect answer
Community Expert
October 14, 2020

Try using this code as custom validation script of MODEL field:

var seti = this.getField("G1CDU");

if (event.value == "G2500") {
seti.clearItems();
seti.insertItemAt("Item3");
seti.insertItemAt("Item2");
seti.insertItemAt("Item1");
} else if ( event.value == "ONYX"){
seti.clearItems();
seti.insertItemAt("Item6");
seti.insertItemAt("Item5");
seti.insertItemAt("Item4");
}

Known Participant
October 14, 2020

Thank you for your help. I tried the if statement like yours. I have figured it out.

I was using javascript in custom calculation script. Now, I'm using it in custom validation script and it is working fine.

Thank you.