Remove option and add option is not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2023 11:10 AM
Hi all,
The requirement here is to remove option L2 support subcategory when the category is Process Knowledge/System Questions and country is other than Korea , Vietnam , Japan, Thailand. I have written an on change catalog client script which works on change of category . But add option and remove option lines are not working though it is going inside the loop. Please help me out in this. Below is the script for the same.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var country_name = g_form.getValue('u_country');
g_form.addInfoMessage(country_name);
g_form.clearOptions('subcategory');
if (country_name != 'KR' && country_name != 'VN' && country_name != 'TH' && country_name != 'JP') {
if (newValue == "Process Knowledge/System Questions") {
g_form.addInfoMessage(country_name);
g_form.addInfoMessage("1");
g_form.removeOption('subcategory', 'L2 Support');
}
} else {
g_form.addOption('subcategory', 'L2 Support', 'L2 Support');
g_form.addInfoMessage('55');
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2023 10:50 PM - edited 08-13-2023 10:52 PM
https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0678206
"removeOption does not worth through client script access to variable fields on task records"
...
"g_form.removeOption is not supported"
There is a Workaround though: You need to replace all occurrences of
"g_form.removeOption" with "g_sc_form.removeOption"
"g_form.addOption" with "g_sc_form.addOption"
e.g.:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var country_name = g_form.getValue('u_country');
g_form.addInfoMessage(country_name);
g_form.clearOptions('subcategory');
if (country_name != 'KR' && country_name != 'VN' && country_name != 'TH' && country_name != 'JP') {
if (newValue == "Process Knowledge/System Questions") {
g_form.addInfoMessage(country_name);
g_form.addInfoMessage("1");
g_sc_form.removeOption('subcategory', 'L2 Support');
}
} else {
g_sc_form.addOption('subcategory', 'L2 Support', 'L2 Support');
g_form.addInfoMessage('55');
}
}