Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Schedule Report on 3rd working day of each month

Sravani39
Tera Contributor

Hi All,

Have a Requirement to Schedule a report on 3rd working day of each month.

Thanks

8 REPLIES 8

D Dollbaum
Tera Contributor

what is the context of the scheduled report being run?  Is the report for data over a specific period of time (e.g. the most recently completed month) or is it specific to the state of things on the 3rd business day? 

Hi, So the requirement is there is a monthly report created (eg:monthly created incidents report) which need to be scheduled every 3rd day every month. And it should not be a weekend the 3rd day should be a working day

Thanks

 

So the data needs to include the 1st and 2nd of the month (as the end date) - just seeing if the content of the report was independent of the day it was run. 

I think this is likely one for the coding experts.  Will be curious to see the answer as well.

Ravishankar RS
Tera Contributor

Hi Sravani. Even I had the same kind of requirement. 

 

1. Create a schedule and entries where it excludes weekends from "cmn_schedule" table.

2. Create a scheduled Job which runs daily and checks for 3rd or 4th working day.

3. If the condition satisfies then call our report inside and force execute it. Else it will be false.

4. Create your scheduled report.

Have attached screenshot for your reference.

1.PNG3.PNG2.PNG

 

Scheduled Job : 

function checkIfForthDay() {
var grSchedule = new GlideRecord('cmn_schedule');
if (grSchedule.get('name', 'your schedule name')) {
var schedule = new GlideSchedule(grSchedule.sys_id);
var startDate = new GlideDateTime();
startDate.setValue(gs.beginningOfThisMonth());
// startDate.setValue('2023-09-01 12:00:00'); // Testing Purpose (Beginning of the month)
var days = 3;
var dur = new GlideDuration(60 * 60 * 24 * 1000 * days);
var forthDay = schedule.add(startDate, dur);
var today = new GlideDateTime();
// today.setDisplayValue('2023-09-05 12:00:00'); // Testing Purpose (Today's Date)
var todayx = today.getDayOfMonthUTC();
var forthx = forthDay.getDayOfMonthUTC();
if (todayx == forthx) {
var schRpGr = new GlideRecord("sysauto_report");
schRpGr.get("sys id of your scheduled report");
gs.executeNow(schRpGr);
} else {
return false;
}
}
}

Note : If you want to schedule on the 3rd working day then the days value will be = 2. According to the working day you can change the "days" value. 

 

If you find this as a solution please mark as helpful.

Thanks,

Ravi