query records on specified date

Sravan Kumar Ka
Tera Contributor

how to specify condition in addQuery() to return records of a specified date.  

1 ACCEPTED SOLUTION

AbhishekGardade
Giga Sage

Can you please elaborate your requirement?

You can use EncodedQuery like below. You can check out this document for encoded query:

https://docs.servicenow.com/bundle/madrid-platform-user-interface/page/use/using-lists/task/t_GenEnc...

Sample script:
var dat = "sys_created_onON2019-07-24@javascript:gs.dateGenerate('2019-07-24','start')@javascript:gs.dateGenerate('2019-07-24','end')";
var gr = new GlideRecord('incident');
gr.addEncodedQuery(dat);
gr.query();
while(gr.next()){
gs.print(gr.number);

}

Please mark as Correct Answer/Helpful, if applicable.
Thanks!
Abhishek Gardade

Thank you,
Abhishek Gardade

View solution in original post

5 REPLIES 5

AbhishekGardade
Giga Sage

Can you please elaborate your requirement?

You can use EncodedQuery like below. You can check out this document for encoded query:

https://docs.servicenow.com/bundle/madrid-platform-user-interface/page/use/using-lists/task/t_GenEnc...

Sample script:
var dat = "sys_created_onON2019-07-24@javascript:gs.dateGenerate('2019-07-24','start')@javascript:gs.dateGenerate('2019-07-24','end')";
var gr = new GlideRecord('incident');
gr.addEncodedQuery(dat);
gr.query();
while(gr.next()){
gs.print(gr.number);

}

Please mark as Correct Answer/Helpful, if applicable.
Thanks!
Abhishek Gardade

Thank you,
Abhishek Gardade

Jaspal Singh
Mega Patron
Mega Patron

Hi Sravan,

 

Can you elaborate it in more detail as for addQuery('date_field_name','value_of_date'); would be the syntax that is to be used where date_field_name will be the field from table that is Gliderecorded. Also, you may check wiki link for better understanding.

 

Thanks,

Jaspal Singh

 

Hit Helpful or Correct on the impact of response.

lmundere
Kilo Sage

hey, if you want to query records let us say incident created on a specific date/time, you can use something like this:

 

var gr = new GlideRecord('incident');
gr.addQuery('sys_created_on', '2019-05-13 13:45:34');
gr.query();
while(gr.next()){
gs.print(gr.number);
}

Inactive_Us1889
Kilo Explorer

you can copy the filter query related to that table and use addEncodedQuery() instead