Determine if date is within a schedule

abrahams
Kilo Sage

I am having issues with my script not always performing as expected.   I've tried to determine why it is so inconsistent.   Time within the schedule consistently work however It is a rather hit and miss when time is outside of the schedule.   I can't quite determine why or what is causing it to fail.   Would anyone have any ideas?   Below is my script.

if (current.isNewRecord()) {

// Determine if date is within the schedule

var schedID = '<<sys_id of the schedule is entered here>>';   // Business Hours 7-4:30 weekdays excluding holidays

var sched = new GlideSchedule(schedID);

if(!sched.isInSchedule(new GlideDateTime())) {

  current.u_after_hours_call = true;

  current.u_after_hr_system_checked = true;

}

}

1 ACCEPTED SOLUTION

abrahams
Kilo Sage

ServiceNow couldn't find any issue with my script either.   They did suggest not to use the sys_id directly in my script but to look up the sys_id by schedule name.



I determined what the issue was.   My script was working as it should.   I am a bit embarrassed to say that the issue was not all scenarios were accounted for.


View solution in original post

8 REPLIES 8

Hmm.. you shouldn't need that. It should be working I haven't used "isInSchedule" so much, but the few times it seems to be working, thou you're making me nervous now...



I would put a ticket to HI and see what they say.


I will place a ticket on the HI and update this when I hear.


abrahams
Kilo Sage

ServiceNow couldn't find any issue with my script either.   They did suggest not to use the sys_id directly in my script but to look up the sys_id by schedule name.



I determined what the issue was.   My script was working as it should.   I am a bit embarrassed to say that the issue was not all scenarios were accounted for.


Well, the main thing is that you got it working