
- 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 03:02 AM
Hi Jerome,
First, try to clear all the field's value,s and on the basis of the condition use the addOption method to add the values in the Impact field.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
var contract = g_form.getValue('u_service_contract');
g_form.clearOptions('u_service_contract');
call the Ajax
if(true){
g_form.addOption('imapct','Your value'); //add all the options to show
}
else {
g_form.addOption('impact', 'Your values'); //add all the option to show
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2022 06:21 AM
Hi Gaurav,
I tried like that, but still, it's adding blank lines instead of the actual values.
Any other ideas ?
Thanks,
Jérôme
- 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
07-02-2025 12:07 PM
It works! Thanks!