We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

Check for more values in the if condition

Harish74
Tera Expert

Hi,

I'm trying to write an "if" block to check for some values. I have got more values to verify in the if statement of a Business rule. The script is working fine. But I'm trying to find easy and best practice to achieve this. 

if(current.u_level_3.name=='IT Service Systems'||current.u_level_3.name=='Marketing'||current.u_level_3.name=='Sales'){
		//
	}

Please help me the easiest way to achieve this.

2 REPLIES 2

Mark117
Tera Expert

Easiest option would be to use an array of values then check the result using indexOf, so something along the lines of:

var valuesArray = [
    'IT Service Systems',
    'Marketing',
    'Sales'
// insert other values into the array as needed
];

var l3val = current.u_level_3.getValue('name');

if (valueArray.indexOf(l3val) === -1) {
    // Value is not in the list
} else {
    // Value is in the list
}

User177031
Kilo Guru

Use Switch Case method. refer to below URL.

https://www.w3schools.com/js/js_switch.asp