- 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-03-2019 03:07 AM
my reading of your requirement was that you wanted the incidents within your parameters relative to the last 3 days.
if that is not the case please restate your requirement clearly
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-03-2019 07:24 AM
It's all records for a given day and not a range of days relative to the current date. It was in the original question I believe.
- 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
‎06-06-2019 06:51 PM
You could use 'relative' filter twice to narrow down the number of days ago, first one with 'on or after' and second with 'before'.
For e.g.
you can copy the encoded query if you want to use it in a script.
This worked for me.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-04-2021 03:46 AM
Sometimes I like to reply to these "old" questions when I have a similar problem and finds a workaround.
In this case I would do this (using this in a scheduled job) to get records which have a exact due date 5 days from today.
It seems like somewhat the same thing that you where having trouble with.
Part of my script:
var upcomingDueDate = new GlideDateTime();
//add 5 days to current date
upcomingDueDate.addDaysLocalTime(5);
//build querystring to use in gliderecord call later on - query only finds tasks which have this exact due date
var queryString ="state=-6^due_dateON" + upcomingDueDate.getDate() + "@javascript:gs.dateGenerate('" + upcomingDueDate.getDate() + "','start')@javascript:gs.dateGenerate('" + upcomingDueDate.getDate() + "','end')";
....of course you then use the querystring variable in a regular gliderecord call.
Maybe it can be done in a better way - but it works for me 😉