- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2020 11:24 PM
How to stop schedule job to trigger on Holidays. I have updated all holidays in Schedules.
Thanks & Regards,
S.Swaroop.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2020 03:37 AM
Okay.
I added few logs and made few changes. can you chck and share the output.
var answer = false;
var s = new GlideSchedule("e939ddfcdb2c98501317f27139961981");
var w = new GlideSchedule("55ebbbf15f002000b12e3572f2b47714");
var a = gs.nowDateTime();
var gdt = new GlideDateTime();
gs.log(gdt);
if(gdt.getDayOfWeek() > 1 || gdt.getDayOfWeek() < 5){
gs.log("Entered here 1");
if(s.isInSchedule(gdt)&&!w.isInSchedule(gdt)){
gs.log("Entered here 2");
answer = true;
} else {
gs.log("Entered into else of inSchedule condition");
answer = false;
}
} else {
gs.log("entered into else condition of week");
answer = false;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2020 12:36 AM
Hi Swaroop,
So both the condition should be satisfied; please update as below
1st check if it is holiday; if not then check for business hours
var answer = shouldRun();
function shouldRun(){
var s = new GlideSchedule("e939ddfcdb2c98501317f27139961981"); - For Business hours
var w = new GlideSchedule("55ebbbf15f002000b12e3572f2b47714"); - For Holidays
var gdt = new GlideDateTime();
// check if it is not holiday
if(!w.isInSchedule(gdt)){
// it is not a holiday; check the second schedule now
if(gdt.getDayOfWeek() > 1 || gdt.getDayOfWeek() < 5){
return true;
}
return false; // not week day
}
return false; // it is holiday
}
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2020 12:43 AM
Hello Ankur,
if(!w.isInSchedule(!a)) - This condition is not working properly. It was triggering Schedule Job if it was a holiday as well.
Thanks & Regards,
S.Swaroop.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2020 12:51 AM
Hi Swaroop,
!a is not proper; a is object of GlideDatetime and ! of that doesn't make sense
I have updated script above; please try with that;
Also no need of 2 GlideDateTime() objects; so I have kept only 1 i.e. gdt
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2020 01:03 AM
Hello Ankur,
I have tried using - if(!w.isInSchedule(a)), but still this condition is not stopping Schedule job to trigger.
Thanks & Regards,
S.Swaroop.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2020 01:23 AM
Hi Swaroop,
Is today i.e. 8th May a holiday in your schedule? since it would take today's date/time
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader