Help to Make Scheduled Jobs to Run Only on Weekdays
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2025 01:39 AM
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?
(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
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2025 04:02 AM
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;