- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-18-2011 04:59 PM
Im trying to determine if a given date is within a given schedule.
I am not able to follow the following article as there is a note saying: "Functionality described here is obsolete"
http://wiki.service-now.com/index.php?title=Verify_if_dateTime_is_Within_Calendar_Hours
I have tried following this info and was not able to get it either:
Placing time/date conditions inside a business rule script
Here is the code that I am running:
//Get a schedule by name to see if we are currently in the schedule
var schedRec = new GlideRecord('cmn_schedule');
schedRec.get('name', 'test');
gs.addInfoMessage('Checking against schedule: ' + schedRec.sys_id);
var sched = new Packages.com.glide.schedules.Schedule(schedRec.sys_id);
if(sched.isInSchedule(gs.nowDateTime())){
gs.addInfoMessage('in schedule');
}else{
gs.addInfoMessage('not in schedule');
}
gs.addInfoMessage('reached end');
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-19-2011 05:07 PM
The above code wasn't working because the 'isInSchedule' method takes in a GlideDateTime object and not a string.
This code works instead:
var schedRec = new GlideRecord('cmn_schedule');
schedRec.get('name', 'test');
gs.addInfoMessage('Checking against schedule: ' + schedRec.sys_id);
var sched = new Packages.com.glide.schedules.Schedule(schedRec.sys_id);
if(sched.isInSchedule(new GlideDateTime())){
gs.addInfoMessage('in schedule');
}else{
gs.addInfoMessage('not in schedule');
}
gs.addInfoMessage('reached end');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-18-2011 05:20 PM
It appears that package is no longer available.
Check this out:
http://wiki.service-now.com/index.php?title=Calculate_Duration_Given_a_Schedule
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-19-2011 06:28 AM
The method isInSchedule requires a GlideDateTime parameter.
if(sched.isInSchedule(new GlideDateTime())){
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-19-2011 05:08 PM
Thanks John, hadn't seen your reply.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-04-2012 12:07 AM
Hi All,
I have similar kind of requirement.
I have to calculate hours outside the schedule.
If my start time on the form is 8 am and my schedule time is 9 am , then there is a difference of 1 hour.
I need to get this difference, but the problem is, schedules doesn't return the negative value and hence I am stuck..............
Any Help would be much appreciated.
Best Regards,
Namrata Jain