How do you automatically update report date range?

MichaelCreatura
Tera Guru

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? 

find_real_file.png

Many thanks in advance for any advice! 

 

5 REPLIES 5

Rahul Talreja
Mega Sage
Mega Sage

Hi Michael,

Can you please try using below conditions find_real_file.png

Here 10080 is the total minutes in a week

Regards,
Rahul

Please mark my response correct/helpful as applicable!
Thanks and Regards,
Rahul

suvro
Mega Sage
Mega Sage

YOu can also use created on last 7 days

Ankur Bawiskar
Tera Patron
Tera Patron

@MichaelCreatura 

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

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

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"?