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

can you add your script here. 

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {

return;
}
if((newValue == '1a') ||(newValue == '1b) ||(newValue == '1c') )
{
g_form.addOption('drop_down2','2a'); //drop_down field value of dropdown 2 variable
g_form.removeOption('drop_down2','2b');
g_form.removeOption('drop_down2','2c');


}
else if(newValue == '1d')
{
g_form.addOption('drop_down2','2b');
g_form.removeOption('drop_down2','2a');
g_form.removeOption('drop_down2','2c');

}
}

 

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

There are two problems.

1. on adding 3 parameter ( "field, choice and label)  in dropdown its showinf choice and lable both.

2. by default its taking addoption value (for eg, 2a is set in dropdown drop_down2 when 1a is selected in drop_down1 then by default is showinf 2a also with 2b for drop_down2 when 2a is selected in drop_down1)

comment below line from your script then your script will run on page load as well as field change. 

 

//if (isLoading || newValue == '') {

//return;
//}