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

Brad Tilton
ServiceNow Employee
ServiceNow Employee

The created field is actually named sys_created_on, so I would start by switching that name out.


Hello Brad,



Thanks for that prompt response.


I followed your suggestion but there is some kind of syntax error in the line I highlighted above.


Ahh yes, you don't need to use jexl notation inside the g:evaluate block. Take a look at the text in italics.



<g:evaluate var="jvar_incident" object="true" jelly="true"> //add the jelly parameter


var gr = new GlideRecord('u_my_incidents');


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


gr.addQuery('created_on','<=', jelly.jvar_incidet_date); //change here


gr.query();


gr;


</g:evaluate>


Brad,



This is the error line populated to me  



find_real_file.png