Skip to main content
Participating Frequently
June 29, 2022
Answered

How to populate a different dropdown list based on selection of a value in the first dropdown field?

  • June 29, 2022
  • 1 reply
  • 1034 views

Hi there,

I am trying to make a selection from one drop-down list (Service) that populates different items in the second drop-down list (Units of measure).

I found another similar question in the community but when I use the code (I am not a coder) I keep getting the following error- syntaxError: unterminated string literal 4: at line 5.

 

Here is the code:

if(event.value == "Storage")
this.getField("Unit of measure 2.0.12.1").setItems(["Per Standard* Pallet","Per Non-Standard Pallet","Per Bin","Per Square Foot"]);
else if(event.value == "IN Handling")
this.getField("Unit of measure 2.0.12.1").setItems(["Per Pallet 'IN'","Per Carton 'IN'","]);
else this.getField("Unit of measure 2.0.12.1").clearItems();

if(event.value == "Item1")
this.getField("Dropdown2").setItems(["Item 1","Item 2","Item 3"]);
else if(event.value == "Item2")
this.getField("Dropdown2").setItems(["Item 4","Item 5","Item 6"]);
else this.getField("Dropdown2").clearItems();

  This is not the complete drop-down as I wanted to try it first. Also, I am guessing this would go in the first dropdown field? I would really appreciate some help! 

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

You have an extra quotation mark, remove red part:

this.getField("Unit of measure 2.0.12.1").setItems(["Per Pallet 'IN'","Per Carton 'IN'","]);

1 reply

try67
Community Expert
Community Expert
June 29, 2022

As the error message says, you have an unterminated string in your code, specifically in the last item in the array in this line:

this.getField("Unit of measure 2.0.12.1").setItems(["Per Pallet 'IN'","Per Carton 'IN'","]);

And yes, this code should be used as the custom validation script of the first drop-down.

Participating Frequently
June 29, 2022

Thank you so much for offering your help.

I guess I am asking how to fix this? How do I terminate it? What is the code I need to make it work? I don't see any open square parenthesis. 

 

 

Nesa Nurani
Community Expert
Nesa NuraniCommunity ExpertCorrect answer
Community Expert
June 29, 2022

You have an extra quotation mark, remove red part:

this.getField("Unit of measure 2.0.12.1").setItems(["Per Pallet 'IN'","Per Carton 'IN'","]);