How to schedule a scheduled job only on weekdays?

swathigangadhar
Tera Expert

How to schedule a scheduled job only on weekdays?

8 REPLIES 8

Hi,

I want my schedule to run 1st of every quarter month, which should exclude if 1st falls on a weekend and run the job the next working day so if I use the below will the schedule job just skip if it's a weekend or will it run the next working day.

var gdt = new GlideDateTime();
var dow = gdt.getDayOfWeekLocalTime();
if (dow < 6) {
if (gdt.getMonth() == 1 || gdt.getMonth() == 4 || gdt.getMonth() == 7 || gdt.getMonth() == 10) {
answer = true;
}
}

preddy
Kilo Guru

Hi Swathi,


In Scheduled Jobs please enable the Condition checkbox and paste the below code.



var answer = false;


var now = new GlideDateTime();


if(now.getDayOfWeekUTC() !=6 && now.getDayOfWeekUTC() !=7 )       // this scheduled job will run only on Weekdays


{


      answer = true;


}



Please Hit Like, Helpful or Correct depending on the impact of response


pbusch
Tera Expert

This conditional script works, running Washington DC

 

// Run the scheduled report only on weekdays (Non - Fri)
// 0=Sunday,
// Get today's date and determine which day it Is
var today = new Date();
dayOfWeek = today. getDay();
// It it is Monday, Tuesday, Wednesday, Thursday, or Friday, send report
// If it is Saturday or Sunday, do not send the report.
if (dayOfWeek > 0 && dayOfWeek < 6){
answer = true;
}
else {
answer = false;
}
 
from this post:
Enjoy!
~ "Breynia Disticha"

mihirlimje867
Tera Guru

Hello @swathigangadhar ,

Could you try this script and let me know if it works or not?


var answer = false;

 

var now = new GlideDateTime();

 

if(now.getDayOfWeek() > 0 &&   now.getDayOfWeek() < 6){

 

    answer = true;

 

}


Thank you.
If you think this script will help you please like this.