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

Hi St,

To use Scheduled Reports, set it up to run Daily and set the condition as follows.

var answer = false;
var gdt = new GlideDateTime();
var curDay = gdt.getDayOfMonthUTC();  // current day of month

gdt.setValue(gs.beginningOfThisMonth());

var dow = gdt.getDayOfWeek();
var firstDay = 1;  // default to run report on 1st
if (dow == 6) {  // if Sat, run report on 3rd
  firstDay  = 3;
} else if (dow == 7) {  // if Sun, run report on 2nd
  firstDay  = 2;
}

if (curDay == firstDay) {  // check if current day is the day to run report
  answer = true;
}
answer;

Musab Rasheed
Tera Sage
Tera Sage

Hello ST,

Try like this.? Mark my answer as correct if that helps

Code:

//Return 'true' to run the job
var answer = false;

//Get the day of week. 1=Monday, 7=Sunday
var now = new GlideDateTime();

//Run only on weekdays
if(now.getDayOfWeek() < 6){
   answer = true;
}
answer;
Please hit like and mark my response as correct if that helps
Regards,
Musab

Hi Rasheed,

For example- 1st may was Sunday.. so the scheduling will get excluded ...will it then schedule for 2nd May?