How do you automatically update report date range?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-10-2022 02:17 AM
We produce a report every Tuesday at 4pm based off of multiple ServiceNow reports.
In order to get the data, we open each report individually and update the 'Created' conditions to say that the report should contain records created between 'Last Tuesday' at 16:00 and 'Current Day (Tuesday)' at 15:59:59. For example, this week we updated the conditions on each report to say that they results should be Created Between 31/05/2022 at 16:00:00 and 07/06/2022 at 15:59:59.
Is there a way of automating this (or using a dynamic filter) so that we don't have to manually enter new dates each week when running the report?
Many thanks in advance for any advice!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-10-2022 02:32 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-10-2022 02:42 AM
YOu can also use created on last 7 days
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-10-2022 02:51 AM
no direct way but here is a workaround
1) run schedule job which runs only at Tuesday at 3.50pm and updated the report filter condition
2) the reason I used 3.50pm because your report runs at 4pm
updateCondition();
function updateCondition(){
try{
var gr = new GlideRecord("sys_report");
gr.addQuery("title", "Report Title");
gr.query();
if (gr.next()) {
gr.filter = ''; // give your filter condition here which you want to update
gr.update();
}
}
catch(ex){
gs.info(ex);
}
}
Detailed solution I shared few months ago; enhance it to get current date which will be Tuesday and subtract 7 from it to get last Tuesday and update the dates via script
Can we write script to change reports filter condition?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-10-2022 03:14 AM
What do I write in the gr.filter line?
It should be: Created between current date at 16:00:00 and subtract 7 days at 15:59:59
Also, how do I find the information for the gr. addquery? "Report Title" is that the actual report name? What is "Title"?