How to stop Schedule job to Trigger on Holidays.

Swaroop10
Giga Contributor

How to stop schedule job to trigger on Holidays. I have updated all holidays in Schedules.

 

Thanks & Regards,

S.Swaroop.

1 ACCEPTED SOLUTION

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

View solution in original post

24 REPLIES 24

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

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

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.

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

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

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.

Hi Swaroop,

Is today i.e. 8th May a holiday in your schedule? since it would take today's date/time

Regards
Ankur

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