- 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:30 AM
you can use onChange() client script here , make UI type ALL so it will work for portal as well as native UI.
use g_form.addOption() to show it and g_formRemoveOption() to hide it.
If you have written script then kindly paste it here.
example:
if(g_form.getValue('Dropdown A') == 'Option 1a' && g_form.getValue('Dropdown A') != 'Option 2a' ){
g_form.addOption('Dropdown A','Option 1b','Option 1b');
g_form.removeOption('Dropdown A','Option 2b');
}
else if(g_form.getValue('Dropdown A') != 'Option 1a' && g_form.getValue('Dropdown A') == 'Option 2a' ){
g_form.addOption('Dropdown A','Option 2b','Option 2b');
g_form.removeOption('Dropdown A','Option 1b');
}
Note: make sure about the field value and field name in the script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-16-2019 01:51 AM
Thanks Harshvardhan,
can we use setdisplay for it? fields in both the option are populated from custom table.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-16-2019 01:58 AM
addOption: which used to just show the option on the form , here option is not going to create on sys_choice table.
setdisplay : it used to hide or show the field not the drop down values.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-16-2019 02:24 AM
working with one option value but if I am adding or/and condition or elseif for newValue it not working :
i have reference this as well https://community.servicenow.com/community?id=community_question&sys_id=1e964f25db1cdbc01dcaf3231f96...