Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Schedule Job - need to trigger only on weekdays

anaghas
Tera Contributor

Hi All,

I have a schedule job that needs to be triggered only on weekdays. I've have the calendar chosen as "Mon-Fri 8-5" and Trigger mode "Daily". But the job is triggered everyday including saturday and sunday.

How can I fix this?

Appreciate your inputs.

Thanks!

4 REPLIES 4

Prateek kumar
Giga Sage

Hello Anagha


Check these threads


How to schedule a scheduled job only on weekdays?


https://www.servicenowguru.com/system-definition/weekdaysonly-scheduled-job/



Please mark my response as correct and helpful if it helped solved your question.
-Thanks

Harish KM
Kilo Patron

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;


}



check this also


https://www.servicenowguru.com/system-definition/weekdaysonly-scheduled-job/


Regards
Harish

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"

Not applicable

Hello @anaghas ,
Could you try this code 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 this script will help you please like this.