- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2018 06:23 AM
What I want is query by using from to.
For example,
var rec = new GlideRecord('incident');
rec.addQuery('sys_created_on','<',todate);
rec.addQuery('sys_created_on','>',fromdate);
in server script.
But it doesn't work well.
(fromdate and todate is GlideDateTime Object.)
Does anyone know how?
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2018 06:43 AM
Hi tmiya,
The following script can be helpful:
var fromdate = new GlideDateTime('some start date');
var todate = new GlideDateTime('some end date');
var gr = new GlideRecord('incident');
gr.addQuery('sys_created_on', '>=', fromdate);
gr.addQuery('sys_created_on', '<=', todate);
gr.query();

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2018 06:31 AM
By default just doing multiple addQuery does do an 'and' between all the queries. Can you share the full code and what you are trying to achieve.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2018 06:34 AM
What I would do is use encoded query...
So in SN, go to your Incident table list view and filter by the created date from and to, then right-click the breadcumb and choose 'copy query':
and then in your script do
var rec = new GlideRecord('incident');
rec.addEncodedQuery('sys_created_onBETWEENjavascript:gs.dateGenerate('2018-06-01','00:00:00')@javascript:gs.dateGenerate('2018-07-12','23:59:59');
rec.query();
while (rec.next()) {
}
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2018 06:43 AM
Hi tmiya,
The following script can be helpful:
var fromdate = new GlideDateTime('some start date');
var todate = new GlideDateTime('some end date');
var gr = new GlideRecord('incident');
gr.addQuery('sys_created_on', '>=', fromdate);
gr.addQuery('sys_created_on', '<=', todate);
gr.query();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2018 04:51 PM
Thank you for your reply.
I don't know why it didn't work well yesterday.
Now my program works fine without changeing.
Regards.