
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2022 02:50 AM
Hello
I added the option "4 - No Impact" with value 4 in the impact choice list.
I would like this option to be removed/added based on certain conditions.
I created the following client script to achieve this:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
//Type appropriate comment here, and begin script below
var contract = g_form.getValue('u_service_contract');
var serviceContractAjax = new GlideAjax('ServiceContractAjax');
serviceContractAjax.addParam('sysparm_name', "getCSOCContract");
serviceContractAjax.addParam('sysparm_service_contract', contract);
serviceContractAjax.getXMLAnswer(getServiceTypeCallback);
function getServiceTypeCallback(answer) {
var getCSOCContract = answer;
if (getCSOCContract == "false") { // OCD INTL Entity
g_form.removeOption('impact', 4);
}
}
}
It removes it when I meet the condition, but it doesn't add it back when the condition is not matched.
I tried to add
else {
g_form.addOption('impact', 4);
}
but this only adds blank lines but not the expected value..
Thanks
Jérôme
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2022 06:27 AM
Hi,
Did you try something like below,
g_form.addOption('impact',4, "4 - No Impact"); // this function accepts value and label both
Let me know if you have any further queries.
Please mark this as Correct or Helpful if it helps.
Thanks and Regards,
Abhijit
Community Rising Star 2022
Regards,
Abhijit
ServiceNow MVP

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2022 06:50 AM
It works !! 😄
Thanks a lot 🙂