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.

How to check if state is in one of multiple values

JC S_
Mega Guru

We are writing a server script for a service portal widget and we need to check if state is in one of multiple values.

Our current only checks a single value, what we need is for this to check if state is either -4, -3, -2 and -1. Can we use IN or LIKE here?

if(data.table == 'change_request' && gr.active == true && gr.state == '-4' && gr.requested_by == gs.getUserID()){
//code
}
1 ACCEPTED SOLUTION

Pothuraju
Mega Expert

Hi JC,

we can use (gr.state =='-4'||gr.state =='-3'||gr.state =='-2'||gr.state =='-1')

 

this should work

if(data.table == 'change_request' && gr.active == true && (gr.state =='-4'||gr.state =='-3'||gr.state =='-2'||gr.state =='-1') && gr.requested_by == gs.getUserID()){ //code }

View solution in original post

2 REPLIES 2

Pothuraju
Mega Expert

Hi JC,

we can use (gr.state =='-4'||gr.state =='-3'||gr.state =='-2'||gr.state =='-1')

 

this should work

if(data.table == 'change_request' && gr.active == true && (gr.state =='-4'||gr.state =='-3'||gr.state =='-2'||gr.state =='-1') && gr.requested_by == gs.getUserID()){ //code }

Mohammed_Iqbal
Tera Guru

Hello JC,

for checking multiple values you can use or(||) operator.

like --state==1||state==2||state==3.

 

if(data.table == 'change_request' && gr.active == true &&//then you just use sate in or operator.

(gr.state =='1'||gr.state =='2'||gr.state =='3') && gr.requested_by == gs.getUserID()){

//code

}

 

HOPE THIS HELPFUL!!!!! MARK CORRECT OR HELPFUL.

Thanks,
Mohammed Iqbal