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

ShubhankarK9612
Mega 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 M1
Giga Sage
Giga Sage

Hi @ShubhankarK9612 ,

 

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

HemanthM1_0-1766741559949.png

 

 

Accept and hit Helpful if it helps.

Thank you,
Hemanth
Certified Technical Architect (CTA), ServiceNow MVP 2024, 2025

View solution in original post

Hi @ShubhankarK9612 ,

 

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

Accept and hit Helpful if it helps.

Thank you,
Hemanth
Certified Technical Architect (CTA), ServiceNow MVP 2024, 2025

View solution in original post

13 REPLIES 13

nayanmule
Tera Guru

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!

 

 

 

Accept and hit Helpful if it helps.

Thank you,
Hemanth
Certified Technical Architect (CTA), ServiceNow MVP 2024, 2025

Ankur Bawiskar
Tera Patron
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! 🙏

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Thank you for the response