Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Hide one of the Request category option when a specific ci is selected in Catalog item

VishakhaShi
Tera Contributor

User has a requirement : In a catalog item, when a 'ABC' ci is selected ,  'XYZ' option of request category field should be removed from option.

For this , i used the below script but its not working:

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    var ci = g_form.getValue('configuraion_item');
 
     if (ci == 'CI sys id') {
        var options = g_form.getOptions('request_category');
 
         for (var i = 0; i < options.length; i++) {
            if (options[i].value == 'access_privilege') {
                g_form.removeOption('request_category', options[i].value);
            }
        }
    } else {
       
      g_form.addOption('request_category', 'access_privilege', 'Access & Privilege');
    }
}

 

What is the error here?

1 ACCEPTED SOLUTION

@VishakhaShi You can specify the reference qualifier in the Type specification tab of your look up select box variable.

 

Screenshot 2024-08-26 at 6.06.16 PM.png

View solution in original post

8 REPLIES 8

Sandeep Rajput
Tera Patron
Tera Patron

@VishakhaShi Please update your script as follows.

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    var ci = g_form.getValue('configuraion_item');
 
     if (ci == 'CI sys id') 
     {
       g_form.removeOption('request_category', 'access_privilege');
    } else {       
      g_form.addOption('request_category', 'access_privilege', 'Access & Privilege');
    }
}

 

Tried this but not working.

@VishakhaShi Are you sure that request_category is a select box and not a Look up select box? The addOption and removeOption only work with select box.

Its  Look up select box actually. What is an alternate of addOption and removeOption ?