- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-16-2019 01:13 AM
I have two lookup select drop down
Dropdown A ( Option 1a, Option 2a)
Dropdown B ( Option 1b, Option 2b)
I want to show Option 1b in dropdown B when Option 1a is selected in dropdown A . ( should work on Native UI and portal)
Thanks
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-16-2019 03:02 AM
in first condition single quote is missing.
addOption need 3 parameter.
if(newValue == '1a' || newValue == '1b' || newValue == '1c')
{
alert('if is working ');
g_form.addOption('drop_down2','choiceValue','choiceLabel'); // add here choice label and choice value
g_form.removeOption('drop_down2','2b');
g_form.removeOption('drop_down2','2c');
}
else if(newValue == '1d')
{
alert( 'else if is working ');
g_form.addOption('drop_down2','choiceValue','choiceLabel'); // add here choice label and choice value
g_form.removeOption('drop_down2','2a');
g_form.removeOption('drop_down2','2c');
}
kindly have a look on below doc.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-16-2019 01:59 AM
Hi Sneha,
A better approach for this if the values are populated from a custom table would make the values dependent on the other value.
https://docs.servicenow.com/administer/field_administration/task/t_MakingAFieldDependent.html
Else if the dependency doesn't work in your case then you can write a reference qualifier which will dynamically update the field values when the other value is changed.
Here is the best example, https://www.servicenowguru.com/scripting/script-includes-scripting/advanced-reference-qualifier-scri...
Let me know if you need help with the script or making it dependent. Thanks.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-16-2019 02:03 AM
Hello,
Please Refer Below OnChange Catalog Client Script and Make changes as you needed :
Type : OnChange
Variable name : Category //Dropdown A
UI Type : All
Script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading )
{
g_form.clearOptions("subcategory"); //Dropdown B
g_form.addOption("subcategory","","-- None --");
return;
}
if(newValue == 'A') //Option 1a
{
g_form.clearOptions("subcategory");
g_form.addOption("subcategory","A1","A1"); //Option 1b
g_form.addOption("subcategory","A2","A2");
}
else if(newValue == 'B') //Option 2a
{
g_form.clearOptions("subcategory");
g_form.addOption("subcategory","B1","B1"); //Option 2b
g_form.addOption("subcategory","B2","B2");
}
else
{
g_form.clearOptions("subcategory");
g_form.addOption("subcategory","","-- None --");
}
}
//Refer parameters : addOption(String fieldName, String choiceValue, String choiceLabel);
Make changes as per your Requirement !!!
Regards,
Sanket
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-16-2019 02:25 AM
Hi Saket this is not working, i tried.