If condition: is not one of

Dubz
Mega Sage

Hi All,

Hopefully an easy question; i need to script an if condition to say active = true and state is not 6, 7 or 8. What's the best way to write this, can i comma-separate options or do i need to write out each state individually? I tried option 1 below and it didn't work so not really sure where to go from here.

if(active = true && state != 6 && state != 7 && state != 8){

//stuff here

}

if(active = true && state != 6, 7, 8){

//stuff here

}

if(active = true && state != 6 || 7 || 8){

//stuff here

}

1 ACCEPTED SOLUTION

vinothkumar
Tera Guru

Hi David,



Try add one more bracket before state and it will work.



if(active = true && (state != 6 && state != 7 && state != 8)){  


//stuff here  


}  


View solution in original post

6 REPLIES 6

Aakash Shah4
Tera Guru
  1. if(active = true && (state != 6 || state != 7 || state != 8){  
  2. //stuff here  
  3. }


This is the correct way


You can also use the encoded query function



GlideRecord - ServiceNow Wiki


Hmm this doesn't seem to be working for me. I have this on an onLoad client script that is returning resolution categories depending on various conditions. The script below clears options and then populates the list with an array produced via a GlideAjax, i need to stop this from running when the ticket is in any one of 3 resolved/closed states. I've tried the OR conditions below and i've tried them as AND (&&) as well but neither way seems to work. If i just say && state != 6 if works fine for that state...



if(response.retail == 'true' && type == 'Incident' && (state != 6 || state != 7 || state != 10)){



g_form.clearOptions('close_code');


g_form.addOption('close_code', '', '-- None --', 0);



var incident = response.incidents.split(",");



for(var i =0; i<=incident.length; i++) {


g_form.addOption('close_code', incident[i], incident[i]);



}


}







Actually scratch that, it has worked with the below syntax. it has also highlighted some missing mandatory field provisions in one of my resolution states!!



if(response.retail == 'true' && type == 'Incident' && (state != 6 && state != 7 && state != 10)){



Thanks all for the input