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

Hello Ankur,

Yes for testing purpose i have made 8th May as Holiday in my Schedules.

 

 

Thanks & Regards,

S.Swaroop.

Hello Swaroop,

add gs.log(gdt) and check if you are getting 8th May or 7th May. May be due to timezone, you might be getting 7th because of which the condition might be failing.

Kindly mark the comment as helpful if it helps to solve your problem.

Regards,
Asif
2020 ServiceNow Community MVP

Hello Asif,

I have used the gs.log and it was giving May 8th, which was the date i have used for testing.

 

 

Thanks & Regards,

S.Swaroop.

Hi,

Are you using variable a or gdt in your code?

 if(!w.isInSchedule(a))

Hello Asif,

1) I am using the below code in Schedule Job under "Condition".

var answer = false;
var s = new GlideSchedule("e939ddfcdb2c98501317f27139961981"); - This is for checking Business hours
var w = new GlideSchedule("55ebbbf15f002000b12e3572f2b47714"); - This is for checking Holidays
var a = gs.nowDateTime(); - This i am using to get current Date and time and to validate weather it is coming under Business hours (or) not.
var gdt = new GlideDateTime();

if(gdt.getDayOfWeek() > 1 || gdt.getDayOfWeek() < 5){
if(s.isInSchedule(a)&&!w.isInSchedule(a)){
answer = true;
}
answer = false;
}
answer = false;

2) For Testing of current time, i have created a BR and used below script for testing.

var a = gs.nowDateTime();
gs.addInfoMessage(a);