- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-01-2019 03:12 PM
How would I script to get a count of records relative to the current date? This wouldn't be a range. It would be specific to a specified number of days like 3 days ago, 2 days ago, etc. (eg Get the number of incidents created 3 days ago relative to the current day)
I tried to see if I could get a filter going by using "Created relative on 3 days ago" but I get zero results. I can easily get a range of records by using on before or after but I can't seem to get records when specifying a specific number of days.
Ultimately, I need to get the difference between incidents created vs resolved per day over 3 days. It wouldn't be a total over 3 days.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-04-2019 04:02 PM
It seems like this is a bug that ServiceNow won't fix. The ability to choose a day relative to the current day is not possible per PRB1017188.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-01-2019 04:01 PM
Hello,
I assume you're doing this for a report? You're not really saying how you're trying to obtain this data and you've posted this in the Developer Community section of the forums...so here we'd think scripting...not reporting.
Just trying to clarify.
Thanks!
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
‎04-02-2019 10:13 AM
It wouldn't necessarily be for a report. The request is for a notification to go out if the number if new incidents > number of resolved incidents for 3 consecutive days.
My thought is to run a scheduled job at the end of each day and calculate this in a script. If there is an easier way, any ideas would be great.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-02-2019 10:34 AM
this will get you incidents created within the last 3 days:
var gr = new GlideAggregate('incident');
gr.addEncodedQuery('sys_created_onRELATIVEGE@dayofweek@ago@3');
gr.addAggregate('COUNT');
gr.query();
if (gr.next()){
n = gr.getAggregate('COUNT');
}
gs.print(n);
write a similar script to get incidents resolved within last 3 days (state = 6)
compare the counts.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-02-2019 10:39 AM
Thanks for that. Why doesn't the list filter work the same way?