Client Script - if Statement with "OR" ||

Laurie Marlowe1
Kilo Sage

Hello,

I cannot figure out how to get this "if" statement to work in a client script.   I know it's a syntax issue, but I cannot figure it out.

This works:

  if ((risk == '') && (changeType != 'Standard'))   {

  g_form.removeOption('state',2); // Sumbitted

  }

This does not work (throws a compiler syntax error:

  if ((risk == '') && (changeType != 'Standard')) || ((risk == '') && (changeType != 'Emergency')) {

  g_form.removeOption('state',2); // Sumbitted

  }

This does not work (Submitted option is removed)

  if (((risk == '') && (changeType != 'Standard')) || ((risk == '') && (changeType != 'Emergency'))) {

  g_form.removeOption('state',2); // Sumbitted

  }

I also tried splitting it into two if statements, and that did not work.

Any ideas?

Thanks,

Laurie

1 ACCEPTED SOLUTION

Laurie Marlowe1
Kilo Sage

WAIT!!!!   Hang on to your hats ladies and gentlemen!!!



The solution is do not use "||" !   Use "&&"!



Thanks,



Laurie


View solution in original post

12 REPLIES 12

Dave Smith1
ServiceNow Employee
ServiceNow Employee

Curious to know what you're actually checking for.



It seems that risk needs to be empty, and change is not "emergency" or "standard" - in which case, the && will be needed (because being one of those change types would meet the "not" criteria of the other).



Would it be easier to ask: if risk is empty and change is normal? Or do you have additional change types outside of those three options?


Hi David,



We do have one additional change type called Expedited.  



Thanks,



Laurie


In which case, your condition can be reduced to:



if (risk == '' && changeType != 'Standard' && changeType != 'Emergency' )



.. but I think you mentioned that in your answer, anyway.