Remove choice field when a specific value selected in a reference field.

1_DipikaD
Kilo Sage

Hi All,

When service field in change form is selected as "SAP Enterprise Services" remove choice "low" from Risk field except this addback the choice "low" to the Risk field for other values of service field.

 

I have tried the below onchange clientscript but did not get the desired result :-

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }
   var service = g_form.getValue('business_service');
   var choice = 'risk';
   if(service ==26da329f0a0a0bb400f69d8159bc753d){
    g_form.removeOption(choice,'4');
   }

   //Type appropriate comment here, and begin script below
   
}
8 REPLIES 8

Swapna Abburi
Mega Sage
Mega Sage

Hi @1_DipikaD 

Looks like you missed to put sys_id in quotes.

Ankur Bawiskar
Tera Patron
Tera Patron

@1_DipikaD 

it's not recommended to use hard-coded sysId so please use GlideAjax

For the current script update as this

I have tried the below onchange clientscript but did not get the desired result :-
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }
   var service = g_form.getValue('business_service');
   var choice = 'risk';
   if(service == '26da329f0a0a0bb400f69d8159bc753d){
    g_form.removeOption(choice,'4');
   }

   //Type appropriate comment here, and begin script below
   
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Ankur Bawiskar  Yes, you are right. But what should be the correct approach to use glideajax . 

I have tried the below script in PDI, it's working but in real instance I am not getting the result.

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }
   var service = g_form.getValue('business_service');
   var choice = 'risk';
   if(service == "26da329f0a0a0bb400f69d8159bc753d"){
    g_form.removeOption(choice,'4');
   }
   else {
    g_form.addOption(choice,'4','low');
   }

   //Type appropriate comment here, and begin script below
   
}

 

 

@1_DipikaD 

yes use GlideAjax, store the sysId in system property and then compare

what debugging did you perform in your actual instance?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader