Schedule report on the 1st day on the month excluding weekends
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2022 01:39 AM
How to schedule a report for every 1st of month but if it is weekend then it should trigger next day.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2022 02:06 AM
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
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-16-2022 02:42 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2022 02:50 AM
in script section
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-16-2022 03:17 AM