Query in g:evaluate is not working.

Rohant Joshi2
Kilo Expert

Hi All,

 

I am stuck at a point to complete my task, please guide me on this.

 

I am trying to display all those incidents in a UI Page whose creation date is less than or equal to date selected in my new customized field 'incident_date' on my current incident.

 

For this I have created a UI action on my incident form which is calling the UI Page. For the sake of test to my approach I tried pulling data with query of all the active=true incident and it working fine.

But when I add query for date comparison it is showing me error and the reason is not known to me.

I am adding the code which is giving me error.

 

 

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

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

<style>

 

th, td {

      padding: 5px;

}

</style>

 

<j:set var="jvar_incidet_date" value = "${sysparm_incident_date}" />

 

<g:evaluate var="jvar_incident" object="true">

var gr = new GlideRecord('u_my_incidents');

gr.addQuery('active', 'true');

gr.addQuery('created_on','<=','${jvar_incidet_date}');       --->   error

gr.query();

gr;

</g:evaluate>

1 ACCEPTED SOLUTION

Completely forgot you need to escape the <= in xml. Try this line instead and make sure that your jelly.jvar_incident_date is not in quotes.


gr.addQuery('sys_created_on', '&lt;=', jelly.jvar_incident_date);



Also, you need to make sure to include the jelly attribute:


<g:evaluate var="jvar_incident" object="true" jelly="true">


View solution in original post

10 REPLIES 10

Could you post the most current code you're using?


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


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


<style>


 


th, td {


      padding: 5px;


}


</style>



<j:set var="jvar_incident_date" value = "${sysparm_incident_date}" />



<g:evaluate var="jvar_incident" object="true">


var gr = new GlideRecord('u_gsi_incidents');


gr.addQuery('active', 'true');


gr.addQuery('sys_created_on','<=','jelly.jvar_incident_date');


gr.query();


gr;


</g:evaluate>



<table>


<tr>


<th>Number</th>


<th> Short Description</th>


<th> Incident Date</th>


</tr>



<j:while test="${jvar_incident.next()}">



<tr>


  <td>


    ${jvar_incident.getValue('number')}


  </td>


  <td>


  ${jvar_incident.getValue('short_description')}


  </td>


  <td>


  ${jvar_incident.getValue('u_incident_date')}


  </td>


</tr>



</j:while>



</table>



</j:jelly>


Completely forgot you need to escape the <= in xml. Try this line instead and make sure that your jelly.jvar_incident_date is not in quotes.


gr.addQuery('sys_created_on', '&lt;=', jelly.jvar_incident_date);



Also, you need to make sure to include the jelly attribute:


<g:evaluate var="jvar_incident" object="true" jelly="true">


Thanks Brad!


Before posting this question I do tried with '&lt;' but that dint gave me any result.



May be that was because I was missing to make jelly="true".



Anyhow it working now thanks again.


Cheers!


Thank Brad, you are a life saver