- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-06-2025 02:09 AM
How to create a report of incident created from last month 20th to this month 20th. It should be dynamically updated in dashboard when month changes
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-06-2025 02:41 AM - edited ‎05-06-2025 02:49 AM
1 way is to use script in the report filter condition
1) create client callable classless script include and bring in the incidents created from 20th of last month and 20th of this month, return that array of sysIds
function getIncidents() {
// Get the current date
var currentDate = new GlideDateTime();
// Calculate the 20th of the current month
var currentMonth20th = new GlideDateTime();
currentMonth20th.setDayOfMonth(20);
// Calculate the 20th of the previous month
var previousMonth20th = new GlideDateTime();
previousMonth20th.addMonthsUTC(-1);
previousMonth20th.setDayOfMonth(20);
gs.info(previousMonth20th);
gs.info(currentMonth20th);
var arr = [];
// Create a GlideRecord query for incidents created between previousMonth20th and currentMonth20th
var gr = new GlideRecord('incident');
gr.addQuery('sys_created_on', '>=', previousMonth20th);
gr.addQuery('sys_created_on', '<', currentMonth20th);
gr.query();
// Process the results
while (gr.next()) {
arr.push(gr.getUniqueValue());
}
return arr.toString();
}
2) then in report filter condition use this
sys id [IS ONE OF] javascript: getIncidents();
Note: I have tested the script, but please check and enhance, it gave me correct date as 20th April and 20th May
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-06-2025 02:15 AM
Hi @gautham11 ,
-In the Conditions section, set the filter to include incidents created between last month 20th and this month 20th.
-Use the Advanced filter to dynamically set the date range:
If my response helped, please mark it correct/helpful and close the thread so that it benefits future readers.
Regards,
Mohd Arbaz.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-06-2025 02:20 AM
Hi @mohdarbaz ,
Can you share the screenshot please. I'm not getting option to use above conditions in filter..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-06-2025 02:41 AM - edited ‎05-06-2025 02:49 AM
1 way is to use script in the report filter condition
1) create client callable classless script include and bring in the incidents created from 20th of last month and 20th of this month, return that array of sysIds
function getIncidents() {
// Get the current date
var currentDate = new GlideDateTime();
// Calculate the 20th of the current month
var currentMonth20th = new GlideDateTime();
currentMonth20th.setDayOfMonth(20);
// Calculate the 20th of the previous month
var previousMonth20th = new GlideDateTime();
previousMonth20th.addMonthsUTC(-1);
previousMonth20th.setDayOfMonth(20);
gs.info(previousMonth20th);
gs.info(currentMonth20th);
var arr = [];
// Create a GlideRecord query for incidents created between previousMonth20th and currentMonth20th
var gr = new GlideRecord('incident');
gr.addQuery('sys_created_on', '>=', previousMonth20th);
gr.addQuery('sys_created_on', '<', currentMonth20th);
gr.query();
// Process the results
while (gr.next()) {
arr.push(gr.getUniqueValue());
}
return arr.toString();
}
2) then in report filter condition use this
sys id [IS ONE OF] javascript: getIncidents();
Note: I have tested the script, but please check and enhance, it gave me correct date as 20th April and 20th May
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-06-2025 03:03 AM - edited ‎05-06-2025 04:45 AM
Thank you @Ankur Bawiskar,
But in 2nd point, I'm able to display incidents in Background script as per conditions.. But in report it's not working..
I tried like both Sys ID [is one of] javascript: scriptIncludeName.functionName();
Sys ID [is one of] javascript: new scriptIncludeName.functionName();