- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-01-2016 01:20 PM
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;
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2016 07:43 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-01-2016 01:28 PM
Hi,
I would put a log on it so you can see what times it doesn't work as intended and see if you can see a pattern there.
I can't see anything wrong with it.
//Göran
Från: abrahams
Skickat: den 1 februari 2016 22:20
Till: Göran Lundqvist <goran.lundqvist@ldc.lu.se>
í„mne: - Determine if date is within a schedule
<https://community.servicenow.com/?et=watches.email.thread>
Determine if date is within a schedule
created by Sue Abraham<https://community.servicenow.com/people/abrahams?et=watches.email.thread> in Scripting - View the full discussion<https://community.servicenow.com/message/879691?et=watches.email.thread#879691>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-01-2016 01:37 PM
I Might have similar need, to introduce additional approval during 'freeze' periods, thus I'm following the topic. Thanks for posting.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-01-2016 01:39 PM
It should be a easy thing. Not to complex and pretty much school book example:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-01-2016 01:45 PM
I did a report to see when it fails and when it succeeds. It isn't consistent. Are you suggesting I not use the API? I guess I could try a query against the 'cmn_schedule' table itself to see if that works better.