how to set up a job condition to exclude holidays?

Marina15
Tera Expert

Hello everyone! 

I tried this script, but it returns false

var answer = new GlideSchedule("sys_id").isInSchedule(new GlideDateTime());
gs.log(answer);

 

Marina15_0-1672411983887.png

type exclude

 

I need the schedule job not to work on holidays
how can i do it?

Thanks in advance!

13 REPLIES 13

@Marina15 Please try below code.

 

var sched = new GlideSchedule("<SYS ID OF SCHEDULE HERE>");
var answer = sched.isInSchedule(new GlideDate()+" 10:00:00");
gs.info(answer);
 
Please mark as correct answer if this solves your issue.
Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023

it doesn't work

 

@Marina15 I have tried the below updated code in my PDI. Its works perfectly fine. Please try out this.

 

var sched = new GlideSchedule("<SYS ID OF SCHEDULE HERE>");
var todayDate = new GlideDate()+" 10:00:00";

 

var date = new GlideDateTime();
date.setDisplayValue(todayDate);

 

var answer = sched.isInSchedule(date);
gs.info(answer);

 

Please mark as correct answer if this solves your issue.

Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023

@Marina15 Did you try this? I have tested it in my PDI, it worked fine. So please try it mark as correct answer if this solves your issue.

Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023

@Marina15 You are trying this on global scope or scoped app?

Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023