i created a lookup selectbox on a catalog variable in servicenow, and in reference…
- User
i created a lookup selectbox on a catalog variable in servicenow, and in reference qualifier i put this script and is working fine. i just need to modify it for the remaining 2 variables as well. means if the current.variables.variable1 == true or current.variable.variable2 == true then apply the same logic, means i need to show all the category for these 3 variables. javascript: (function() { var appFilter = [];
if (current.variables.asp_aellocal == 'true') { appFilter.push('ASP - AEL Local'); appFilter.push('P02 - Ports'); } if (current.variables.alp_ael_global == 'true') { appFilter.push('ALP - AEL Global'); } // If no checkbox is selected → return a query that gives NO results if (appFilter.length === 0) { return 'sys_idISEMPTY'; } // Otherwise, build the query normally var query = 'u_catalog_item=' + current.cat_item + '^u_active=true^u_applicationIN' + appFilter.join(','); return query;})();
- Assistant
- User
if (current.variables.asp_aellocal == 'true') { appFilter.push('ASP - AEL Local'); appFilter.push('P02 - Ports'); }
i need to push these two for first 2 variables and for 3rd variable i need to push another
- Assistant
Got it! You want to:
-
For the first two variables (
asp_aellocalandalp_ael_global), push the two categories: and .
-
- User
can we make these in one condition like, current.variables.variable1 ==true || current.variables.variable2 ==true appFilter.push('ASP - AEL Local'); appFilter.push('P02 - Ports'); }
// For second variable (also pushing same two categories) if (current.variables.alp_ael_global == 'true') { appFilter.push('ASP - AEL Local'); appFilter.push('P02 - Ports'); } - Assistant
Yes, absolutely! You can combine the first two variables in a single
ifcondition using the||(OR) operator.So instead of:
if (current.variables.asp_aellocal == 'true') { appFilter.push('ASP - AEL Local'); appFilter.push('P02 - Ports'); } if (current.variables.alp_ael_global == 'true') { appFilter.push('ASP - AEL Local'); appFilter.push('P02 - Ports'); }You can write:
if (current.variables.asp_aellocal == 'true' || current.variables.alp_ael_global == 'true') { appFilter.push('ASP - AEL Local'); appFilter.push('P02 - Ports'); } - User
script is working fine, but the choices will appear based on alphabetical order, is there any way to sort it
- Assistant