How to hide a option from a list collector varaible for a catalog item

raj765_32
Tera Contributor

Hi can anyone help me with the scenario for the catalog item there is a list collector variable which is referencing to access types table, i want to hide a option from the list collector variable for the catalog item only.

option name : Vpn access

 

 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@raj765_32 

is that variable part of some variable set and that variable set is used in multiple catalog items?

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

View solution in original post

5 REPLIES 5

Riya Verma
Kilo Sage
Kilo Sage

Hi @raj765_32 ,

 

Hope you are doing great.

  1. Open the catalog item for  which you want to make modification in variables.
  2. Identify the list collector variable that references the access types table. (make a Note of variable's name or sys_id

  3. Create a new client script for the catalog item from related list "catalog client script" from catalog item formadd the following code snippet:

    function onLoad() {
       var variableName = 'your_variable_name'; // Replace 'your_variable_name' with the actual variable name or sys_id
    
       // Get the reference to the variable
       var variable = g_form.getControl(variableName);
    
       // Check if the variable exists
       if (variable) {
          // Get the dropdown element within the variable
          var dropdown = variable.selectBox;
    
          // Iterate through each option in the dropdown
          for (var i = 0; i < dropdown.options.length; i++) {
             var option = dropdown.options[i];
             
             // Check if the option is the one you want to hide
             if (option.text === 'Vpn access') {
                // Hide the option
                dropdown.remove(i);
                break;
             }
          }
       }
    }

     

  4. Save the client script.

Please make sure to replace 'your_variable_name' with the actual name or sys_id of the variable referencing the access types table in your catalog item.

Please mark the appropriate response as correct answer and helpful, This may help other community users to follow correct solution.
Regards,
Riya Verma

hi riya

below the code i have written

its not working

function onLoad() {
var variableName = 'what_access_do_you_need';

var variable = g_form.getControl(variableName);


if (variable) {

var dropdown = variable.selectBox;


for (var i = 0; i < dropdown.options.length; i++) {
var option = dropdown.options[i];


if (option.text === 'VPN Access') {

dropdown.remove(i);
break;
}
}
}
}

Ankur Bawiskar
Tera Patron
Tera Patron

@raj765_32 

is that variable part of some variable set and that variable set is used in multiple catalog items?

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

hi ankur no its not a varibale set its just a variable