How to use "AND" operator in ServiceNow UI page using Javascript?

Aru_
Kilo Explorer

I tried "&&" symbol its not working. Someone suggest me which symbol comes in the place of AND in below code:

 

If(Condition1==true AND Condition2==true)

{

}

 

7 REPLIES 7

benjamin_alldri
Mega Expert

Inside of Javascript, there should be no issue with using && as it's an ECMAscript (the standard Javascript is based upon) logical operator. The AND keyword won't work as it's not recognised as a valid operator.

^ also won't work as in Javascript it's a bitwise XOR operator.

A single & is the bitwise AND operator.

What is the specific error you're encountering? There's every possibility it's a code error rather than a language construct one.

Aru_
Kilo Explorer

Hi benjamin,

Inside the servicenow UI page "&" operator not working.It shows error "The entity name must immediately follow the '&' in the entity reference."

 

Try converting your && to && in your script and see if that makes a difference.

It seems like you're running into an XML entity reference error, because the ampersand is one of its protected operators and && fails the operator entity reference.

 

Alternatively, in general XML best practice terms, you could wrap your code in CDATA tags like so:

<![CDATA[
  ... code
]]>

The idea there is that you force the parser to treat the data as potentially volatile, that is it won't interpret it as XML and instead takes it as the character data as literal.