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

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Swaroop,

So you have a schedule which has list of holidays; you will have to use condition in the scheduled job;

check if today falls in that schedule; give the schedule sys_id in the script below

conditional checkbox as true;

new GlideSchedule("schedule_sys_id").isInSchedule(new GlideDateTime());

find_real_file.png

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,

I have a schedule job which will trigger on weekdays and between business hours. for that i have written a script,

var answer = false;
var s = new GlideSchedule("e939ddfcdb2c98501317f27139961981");
var a = gs.nowDateTime();
var gdt = new GlideDateTime();

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

But in that script i should write a condition like this schedule job shoudlnot trigger on holidays. how to configure that condition in the above script.

 

 

Thanks & Regards,

S.Swaroop.

Hi Swaroop,

What is your scheduled; is it Monday to Friday excluding weekends and holidays; if yes then you can just use this in script

Can you share your schedule screenshot

new GlideSchedule("schedule_sys_id").isInSchedule(new GlideDateTime());

Regards
Ankur

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

Hello Ankur,

I have two schedules

1) one is for Business hours.

2) another one is for holidays.

Requirement - Schedule job should trigger on weekdays and between business hours and it should not be a holiday on that day.

For that i have written the below script.

var answer = false;
var s = new GlideSchedule("e939ddfcdb2c98501317f27139961981"); - For Business hours
var w = new GlideSchedule("55ebbbf15f002000b12e3572f2b47714"); - For Holidays
var a = gs.nowDateTime();
var gdt = new GlideDateTime();

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

But it was not working as expected.