Why " isInSchedule() " always entering Else part
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-12-2024 09:32 AM - edited ‎04-12-2024 11:08 AM
Hi All,
I tried below , but it's always entering into ELSE Part.
It's returning UTC time value but I'm looking at EST timezone value validation.
var now= new GlideDateTime();
var nowDate = new GlideDateTime(now.getDisplayValueInternal());
var schedule = new GlideSchedule("090eecae0a0a0b260077e1dfa71da828"); 8-5 working days sys-id I took
if (schedule.isInSchedule(nowDate)) {
gs.info('It is in Schedule');
}else{
gs.info('It is Not in Schedule ');
}
always returning ' It is Not in Schedule '
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-13-2024 03:23 AM - edited ‎04-13-2024 03:26 AM
Hi @Supriya25 ,
Please check below article it might be helpful -
https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0787349
Thanks,
Astik

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-13-2024 05:34 AM
Hi @Supriya25 ,
I checked your problem in my PDI, but unfortunately I didn't find that sys_id that you mentioned "090eecae0a0a0b260077e1dfa71da828", may be could you please tell me from where you got that sysId.
Thanks and Regards
Sarthak
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-13-2024 06:02 AM - edited ‎04-13-2024 06:12 AM
Hi @Supriya25
The following code works for me:
var now= new GlideDateTime();
//var nowDate = new GlideDateTime(now.getDisplayValueInternal());
var nowDate = new GlideDateTime(now.getDisplayValue());
gs.info ("Checking date = " + nowDate);
var schedule = new GlideSchedule("090eecae0a0a0b260077e1dfa71da828"); // 8-5 weekdays excluding holidays
if (schedule.isInSchedule(nowDate)) {
gs.info('It is in Schedule');
}else{
gs.info('It is Not in Schedule ');
}
// now check using a value that is in the schedule, since the above is getting current date-time. and can't be tested until Monday.
nowDate = new GlideDateTime();
nowDate.setDisplayValue("2024-04-15 10:06:00");
gs.info ("Checking date = " + nowDate);
var schedule = new GlideSchedule("090eecae0a0a0b260077e1dfa71da828"); // 8-5 weekdays excluding holidays
if (schedule.isInSchedule(nowDate)) {
gs.info('It is in Schedule');
}else{
gs.info('It is Not in Schedule ');
}
DateTime value is in Local time, not UTC. Output is:
*** Script: Checking date = 2024-04-13 09:11:54
*** Script: It is Not in Schedule
*** Script: Checking date = 2024-04-15 14:06:00
*** Script: It is in Schedule
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-13-2024 09:55 PM - edited ‎04-13-2024 10:06 PM
You have given 2024-04-15 10:06:00, then it should return the Same Date/Time right ? then how come it s returning 14:06:00
10:06:00 means morning time right so it should be in Scheduled. but it is giving 14:06:00.