- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2020 12:07 AM
Hi All,
I am trying addOption & removeOption for selection of resolution category if u_function field change. elseif option is not working, choices are incorrect
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var func = g_form.getValue('u_function');
if(func == 'cad'){
g_form.addOption('u_resolution_category','user_error');
g_form.addOption('u_resolution_category','other');
g_form.removeOption('u_resolution_category','issue');
g_form.removeOption('u_resolution_category','application-bug');
}
else if(func == 'it') {
g_form.addOption('u_resolution_category','application-bug');
g_form.addOption('u_resolution_category','other');
g_form.removeOption('u_resolution_category','issue');
g_form.removeOption('u_resolution_category','user_error');
//Type appropriate comment here, and begin script below
}
else {
g_form.addOption('u_resolution_category','issue');
g_form.addOption('u_resolution_category','other');
g_form.removeOption('u_resolution_category','application-bug');
g_form.removeOption('u_resolution_category','user_error');
}
}
When I choose the "IT" option which matches the elseif condition,but the resolution category choices are removing all options.
Please help me where I am wrong
thanks,
Swetha
Solved! Go to Solution.
- Labels:
-
Incident Management

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2020 12:14 AM
Hi,
Can you try replacing else-if with below.
else if(func == 'it') { alert('Inside else if');
g_form.addOption('u_resolution_category','application-bug');
g_form.addOption('u_resolution_category','other');
g_form.removeOption('u_resolution_category','issue','Issue'); //where Issue is choice label
g_form.removeOption('u_resolution_category','user_error','User Error'); //where User Error is choice label
//Type appropriate comment here, and begin script below
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2020 12:14 AM
Hi,
Can you try replacing else-if with below.
else if(func == 'it') { alert('Inside else if');
g_form.addOption('u_resolution_category','application-bug');
g_form.addOption('u_resolution_category','other');
g_form.removeOption('u_resolution_category','issue','Issue'); //where Issue is choice label
g_form.removeOption('u_resolution_category','user_error','User Error'); //where User Error is choice label
//Type appropriate comment here, and begin script below
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2020 02:34 AM
Thank you, I kept label for addOption & removeOption for all and its working fine.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2020 02:56 AM
Hi,
Can you please try below code (using g_form.clearOptions in if-else loop)
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var func = g_form.getValue('u_function');
if(func == 'cad'){
g_form.clearOptions('u_resolution_category');
g_form.addOption('u_resolution_category','user_error');
g_form.addOption('u_resolution_category','other');
g_form.removeOption('u_resolution_category','issue');
g_form.removeOption('u_resolution_category','application-bug');
}
else if(func == 'it') {
g_form.clearOptions('u_resolution_category');
g_form.addOption('u_resolution_category','application-bug');
g_form.addOption('u_resolution_category','other');
g_form.removeOption('u_resolution_category','issue');
g_form.removeOption('u_resolution_category','user_error');
//Type appropriate comment here, and begin script below
}
else {
g_form.clearOptions('u_resolution_category');
g_form.addOption('u_resolution_category','issue');
g_form.addOption('u_resolution_category','other');
g_form.removeOption('u_resolution_category','application-bug');
g_form.removeOption('u_resolution_category','user_error');
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2020 03:05 AM
Hi,
try this
1) Ensure you clear the options when onChange triggers
2) then add only those options you require to be seen
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var func = g_form.getValue('u_function');
g_form.clearOptions('u_resolution_category');
if(func == 'cad'){
g_form.addOption('u_resolution_category','user_error');
g_form.addOption('u_resolution_category','other');
}
else if(func == 'it') {
g_form.addOption('u_resolution_category','application-bug');
g_form.addOption('u_resolution_category','other');
//Type appropriate comment here, and begin script below
}
else {
g_form.addOption('u_resolution_category','issue');
g_form.addOption('u_resolution_category','other');
}
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader