- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2022 10:34 AM
I need to pull incidents created within past 60 minutes and it should be rolling. e.g. if current date and time is 6/16/2022 14:30:00 then it should bring all the incidents created between 6/16/2022 13:30:00 and 6/16/2022 14:30:00.
I am going to use GlideDateTime to get dates but not sure how to add them in encoded query:
var gdFrom = new GlideDateTime();
var gdTo = new GlideDateTime();
gdTo.subtract(3600000);
var inc = new GlideRecord('incident');
inc.addEncodedQuery('opened_atBETWEEN'); // This is where the question is.
inc.query();
if (inc.next()) {
gs.print(inc.number);
}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2022 12:10 PM
Once you create the query, as Allen said, right click on the very last character in the query and copy the query, then paste it in your encoded query line. There is no need to do any calculations and no need for the GlideDateTime.
Running this in background should give you all incidents created in the last 60 minutes and display the current date/time and the date/time when the incident was created.
var timestamp = new Date().toISOString().
replace(/T/, ' '). // replace T with a space
replace(/\..+/, '') // delete the dot and everything after
var inc = new GlideRecord('incident');
inc.addEncodedQuery('sys_created_onRELATIVEGT@minute@ago@60');
inc.query();
while (inc.next()){
gs.print('Current date/time is ' + timestamp +'. Incident # ' + inc.number + ' was created ' + inc.sys_created_on);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2022 10:56 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2022 11:07 AM
Example please. What do we mean by Relative?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2022 12:10 PM
Once you create the query, as Allen said, right click on the very last character in the query and copy the query, then paste it in your encoded query line. There is no need to do any calculations and no need for the GlideDateTime.
Running this in background should give you all incidents created in the last 60 minutes and display the current date/time and the date/time when the incident was created.
var timestamp = new Date().toISOString().
replace(/T/, ' '). // replace T with a space
replace(/\..+/, '') // delete the dot and everything after
var inc = new GlideRecord('incident');
inc.addEncodedQuery('sys_created_onRELATIVEGT@minute@ago@60');
inc.query();
while (inc.next()){
gs.print('Current date/time is ' + timestamp +'. Incident # ' + inc.number + ' was created ' + inc.sys_created_on);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2022 12:24 PM
Awesome.... Any reference to documentation please. Thank you.