Need to run a schedule job for only on weekdays but without a code change on production

ShubhankarK9612
Tera Contributor

Hi All,

 

I need to modify an existing schedule job for email notifications to run only on weekdays but without a code change on production. And would business calendar help in achieving this in any way? Please see the attached screenshot.

2 ACCEPTED SOLUTIONS

Hemanth M
Tera Sage

Hi @ShubhankarK9612 ,

 

why don't you use Run as weekly and check Monday to Friday - this should work 

HemanthM1_0-1766741559949.png

 

 

View solution in original post

Hi @ShubhankarK9612 ,

 

I don't think so. The earliest you test is tomorrow, since it's the weekend

View solution in original post

13 REPLIES 13

nayanmule
Kilo Sage

Hello @ShubhankarK9612  ,

 

There's no real way for you to schedule this script on weekdays without changing the code. You need to add the condition by clicking the conditional checkbox. 

You can add a below script -

(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
    }
})();

If the script returns true, the job will run , if false the rob will not execute.

 

If my response has helped you, kindly mark it as helpful and accept the solution.

Regards,

Nayan

Hey @nayanmule ,

 

Hang on there are ways to do this!

 

 

 

Ankur Bawiskar
Tera Patron

@ShubhankarK9612 

If you are on Zurich then you can do this with simple config

Zurich's new run types for scheduled jobs 

AnkurBawiskar_0-1766743066024.png

 

If not on Zurich then you need to add script in condition field of your scheduled job

answer = checkCondition();

function checkCondition() {

    var gdt = new GlideDateTime();
    var dayOfWeek = gdt.getDayOfWeekLocalTime();

    // day is not saturday and not sunday
    if (dayOfWeek != 6 && dayOfWeek != 7)
        return true;
    else
        return false;
}

AnkurBawiskar_1-1766743222841.png

 

💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏

Thank you for the response