Using "&&" in <g: evaluate>

prateek10
Kilo Explorer

I am creating a CMS site, i used a ui macro in which i am using a   boolean variable in <g:evalute>. The issue is I am unable to use '&&' in the If condition. I tried using "<![CDATA[   ....]]" and also "&amp;"   but whenever i am trying to print this boolean variable outside< g:evaluate > it returns null.

Any help is appreciated.

5 REPLIES 5

Deepak Ingale1
Mega Sage

You can replatec & by &amp;


so your replaced code would be



&& == &amp;&amp;


bernyalvarado
Mega Sage

Hi Prateek, you should use ${AND} , but you could also use &amp;&amp; in a Jelly test tag.



16 And  

For the same reasons given for the ampersand, use ${AND} to insert a JavaScript and in Jelly. For example:



if (d ${AND} e) var color = d.value;



Alternately, in a Jelly test you would use &amp&amp. For example:



<j:if test="${jvar_form_name == 'sys_form_template' &amp;&amp; !RP.isDialog()}">


source: http://wiki.servicenow.com/index.php?title=Extensions_to_Jelly_Syntax#And



Thanks,


Berny


Thanks Deepak and Berny



I tried both of the option but none of it is working. I am using this to concatenate my multiple condition in if block. here is schema :


<g: evaluate>


boolean false;


if(var1=='abc' &amp;&amp; var2=='xyz'&amp;&amp; var3=='fae' ...........)


{


boolean true;


}


</g:evaluate>



But both the option &amp;&amp; or   ${AND} Not working.


HI Prateek,



It works for me. Perhaps the problem may be that you don't have a space between 'xyz' and &amp.



Here goes the code which works for me:



<?xml version="1.0" encoding="utf-8" ?>


<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">


  <g:evaluate var='jvar_now'>


  var a = true;


  var b = true;


  if (a &amp;&amp; b)


  {


  gs.nowNoTZ();


  }


  </g:evaluate>



  This macro current Date is: <input id="id_test" value='${jvar_now}' />



</j:jelly>



The following is the result:



date.gif



Thanks,


Berny