Schedule report on the 1st day on the month excluding weekends

ST9
Tera Contributor

How to schedule a report for every 1st of month but if it is weekend then it should trigger next day.

 

12 REPLIES 12

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you can schedule it and make it run on 1st day of month

in script check if it's weekend today

a) if yes then check if it's saturday => if yes then run this script which would run it on Monday by adding 2 days

b) if it's sunday => then run this script and it would run on Monday by adding 1 day

something like this

myJob();

function myJob(){

	var gdt = new GlideDateTime();
	var dayOfWeek = gdt.getDayOfWeekLocalTime();
	var trigger = new GlideRecord("sys_trigger");
	if(dayOfWeek == 6){
		gdt.addDaysUTC(2);
		trigger.name = "Job running on Monday due to saturday";
		trigger.next_action = gdt;
		trigger.job_id.setDisplayValue('RunScriptJob');
		trigger.script = getTriggerScript();
		trigger.state = 0;
		trigger.trigger_type = 0;
		trigger.insert();
	}

	if(dayOfWeek == 7){
		var nowTime = new GlideDateTime();
		nowTime.addDaysUTC(1);
		trigger.name = "Job running on Monday due to sunday";
		trigger.next_action = nowTime;
		trigger.job_id.setDisplayValue('RunScriptJob');
		trigger.script = getTriggerScript();
		trigger.state = 0;
		trigger.trigger_type = 0;
		trigger.insert();
	}
}

function getTriggerScript(userSysID) {
	var ret = "new ScriptInclude().functionName()"; // give your script here
	return ret;
}

Regards
Ankur

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

Hi Ankur,

Where i need to add this..is it in condition of schedule report or is it in schedule Job

find_real_file.png

in script section

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

Hi Ankur,

So in Schedule job script, how do i call my report schedule?

find_real_file.png