Show option in dropdown

Sneha39
Mega Guru

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

1 ACCEPTED SOLUTION

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. 

 

https://developer.servicenow.com/app.do#!/api_doc?v=newyork&id=r_GlideformAddOption_String_String_St...

View solution in original post

12 REPLIES 12

Harsh Vardhan
Giga Patron

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. 

 

Thanks Harshvardhan,

  can we use setdisplay for it? fields in both the option are populated from custom table.

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. 

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...