Get a first look at what's coming. The Developer Passport Australia Release Preview kicks off March 12. Dive in! 

Help to Make Scheduled Jobs to Run Only on Weekdays

Mohamed Elsayed
Tera Expert

Hi All,

 

I’ve used the Scheduled Entity Generation feature to set up a daily case for morning checks. However, I need it to run only on weekdays. I’ve made it conditional and applied the script below, but it’s still running on weekends. Any suggestions?

 

MohamedElsayed_0-1737365804686.png

 

(function() {
    var gdt = new GlideDateTime();

    // Get the day of the week (1=Monday, 7=Sunday)
    var day = gdt.getDayOfWeekLocalTime();

    // Check if today is Saturday (6) or Sunday (7)
    if (day == 6 || day == 7) {
        return false; // Do not run the job on weekends
    } else {
        return true; // Run the job on weekdays
    }
})();

 

Regards,

Mo

20 REPLIES 20

Mohamed Elsayed
Tera Expert

I received the following suggested code from ChatGPT, and it worked. However, I still don’t understand why none of the previous codes you suggested worked.

 

var gdt = new GlideDateTime();
var day = gdt.getDayOfWeekUTC();

// Check if today is not Sunday (7) or Monday (1)
day != 7 && day != 1;