How to check if a day is a U.S. Holiday in Script Include
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-24-2022 11:25 AM
I want to check if a certain day is a U.S. holiday. I have a script include for this. No matter what, this always returns false. The schedule I am using is the schedule for U.S. holidays. I call this script include from a scheduled job. I tried adding time zone in the isInSchedule method as well as US\Eastern, but that did not work either. I was wondering how I could get this to work. Thanks!
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-24-2022 11:30 AM
You can use below code to check if day is a US holiday based on schedule.
var g = new GlideRecord('cmn_schedule');
g.addQuery('name', '8-5 weekdays excluding holidays');
g.query();
if (g.next()) {
var sched = new GlideSchedule(g.sys_id);
var d = new GlideDateTime();
d.setDisplayValue("2020-12-25 12:00:00");
if(sched.isInSchedule(d))
gs.info("not a holiday");
else
gs.info("this is a holiday");
}
Regards,
Sachin

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-24-2022 12:30 PM
Go to the Schedule record and click the "Show Schedule" Related Link and see what it looks like.
Its an issue with the schedule. I see that if I run
You may need to revers your if statement logic.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-24-2022 04:57 PM
Hi AM,
It's explained in the following Now Support page.
https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0792369
Scheduled Entries under U.S. Holidays have type "Excluded" so those dates are excluded.
To use U.S. Holidays as it, it's necessary to use them as a child Schedule.
To use U.S. Holidays directly, it's necessary to change the "Type" of Scheduld Entries to "None".
Execution result:
Script:
var g = new GlideRecord('cmn_schedule');
if (g.get('name', 'U.S. Holidays')) {
var schedule = new GlideSchedule(g.sys_id);
var gdt = new GlideDateTime();
gdt.setDisplayValue('2021-12-25 10:00:00');
if (schedule.isInSchedule(gdt)) {
gs.info('Is holiday');
} else {
gs.info('Not holiday');
}
}
Result:
*** Script: Is holiday