Combined Queries in ServiceNow

spgupta
Tera Contributor

How to write sysparm_query for the following condition?

FYI, I am using tables API 

(sys_updated_on == $time AND sys_id = $id) OR (sys_updated_on > $time)

5 REPLIES 5

Juhi Poddar
Kilo Patron

Hello @spgupta 

  • Please refer this script:

 

// Define dynamic values for time and ID
var time = '2024-11-07'; // Replace this with the dynamic value
var id = '2368902653030010b87bddeeff7b12d5'; // Replace this with the dynamic value

// Construct the sysparm_query
var sysparm_query = "sys_updated_onON${time}@javascript:gs.dateGenerate('${time}','start')@javascript:gs.dateGenerate('${time}','end')^sys_id=${id}^NQsys_updated_on>javascript:gs.dateGenerate('" + time + "','start')";

var gr = new GlideRecord('sys_user'); //replace table name
gr.addEncodedQuery(sysparm_query);
gr.query();
while(gr.next()){
	gs.print(gr.name);
}

 

  • Conditions set to build query

JuhiPoddar_0-1732468805305.png

Result:

JuhiPoddar_1-1732468867848.png

Hope this helps!

 

"If you found my answer helpful, please like and mark it as an "accepted solution". It helps others find the solution more easily and supports the community!"

 

Thank You
Juhi Poddar