- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-02-2022 01:45 AM
Hi Team,
I need to add and remove options based on country (select box) selection. When India, china, singapore, korea and germany is chosen "USB-A and USB-A Nano" should appear but when other country is chosen only "USB-C" should be displayed
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var loc = g_form.getValue('country');
// removed option by default
g_form.removeOption('preferred_form', '2');
g_form.removeOption('preferred_form', '1');
g_form.removeOption('preferred_form', '3');
if (loc == '8938b7111b121100763d91eebc0713ec' || '4d38b7111b121100763d91eebc0713eb' || '4938b7111b121100763d91eebc0713ed' || 'c538b7111b121100763d91eebc0713eb' || '9138b7111b121100763d91eebc0713f6') //India, china, singapore, korea and germany Sys_ID
{
g_form.addOption('preferred_form', '1','USB-A');
g_form.addOption('preferred_form', '3','USB-A Nano');
}
else if(loc != '8938b7111b121100763d91eebc0713ec' ||
'4d38b7111b121100763d91eebc0713eb' || '4938b7111b121100763d91eebc0713ed' || 'c538b7111b121100763d91eebc0713eb' || '9138b7111b121100763d91eebc0713f6')
{
g_form.addOption('preferred_form', '2','USB-C');
}
}
Regards,
Priyanka
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-02-2022 02:04 AM
Hi,
So what's not working?
I would suggest this
1) clear all the options when onChange runs and then add the required options
Update as this
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var loc = g_form.getValue('country');
var locationList = '8938b7111b121100763d91eebc0713ec,4d38b7111b121100763d91eebc0713eb,4938b7111b121100763d91eebc0713ed,c538b7111b121100763d91eebc0713eb,9138b7111b121100763d91eebc0713f6';
// removed option by default
g_form.clearOptions('preferred_form');
if (locationList.indexOf(loc) > -1) //India, china, singapore, korea and germany Sys_ID
{
g_form.addOption('preferred_form', '1','USB-A');
g_form.addOption('preferred_form', '3','USB-A Nano');
}
else{
g_form.addOption('preferred_form', '2','USB-C');
}
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-02-2022 01:57 AM
Modify your script:
if (loc == '8938b7111b121100763d91eebc0713ec' || loc == '4d38b7111b121100763d91eebc0713eb' || loc =='4938b7111b121100763d91eebc0713ed' || loc == 'c538b7111b121100763d91eebc0713eb' || loc == '9138b7111b121100763d91eebc0713f6')
do the same in else if block as well
Aman Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-02-2022 02:04 AM
Hi,
So what's not working?
I would suggest this
1) clear all the options when onChange runs and then add the required options
Update as this
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var loc = g_form.getValue('country');
var locationList = '8938b7111b121100763d91eebc0713ec,4d38b7111b121100763d91eebc0713eb,4938b7111b121100763d91eebc0713ed,c538b7111b121100763d91eebc0713eb,9138b7111b121100763d91eebc0713f6';
// removed option by default
g_form.clearOptions('preferred_form');
if (locationList.indexOf(loc) > -1) //India, china, singapore, korea and germany Sys_ID
{
g_form.addOption('preferred_form', '1','USB-A');
g_form.addOption('preferred_form', '3','USB-A Nano');
}
else{
g_form.addOption('preferred_form', '2','USB-C');
}
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-02-2022 02:33 AM
Hi Ankur,
can we not have none option added for this?
Regards,
Priyanka

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-02-2022 02:39 AM
You can remove the none option in variable itself.
In the type specification tab of your variable there is a check box called 'include none'
Regards,
Sumanth