isInSchedule not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2023 07:58 AM
For the script below, the schedule (shift 1)'s sys_id was checked countless times and we're pulling in the correct schedule that is 8-5 weekly, every M, T, W, T, F.
The test time we are testing with is at 10:00:00 which is well within the window of the shift but we keep getting a NO returned. Below is a screenshot of the calendar that SN is showing that the schedule is every workday.
Am I doing something wrong?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2023 08:22 AM - edited 06-26-2023 08:23 AM
Hi @e_wilber
Modify below code and see if it works
var schedRec = new GlideRecord('cmn_schedule');
schedRec.get('dde09e971b9b291041c20e91604bcb1d');
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');
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2023 08:41 AM
Hi,
Unfortunately that just gives off errors when running as a background script for testing as it says we can't access the API this way.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2023 08:47 AM
Try with below script. It should work
var glide = new GlideRecord('cmn_schedule');
glide.addQuery('sys_id', 'Add sys_id of schedule'); //add sys_id
glide.query();
if (glide.next()) {
var sched = new GlideSchedule(glide.sys_id);
var date = new GlideDateTime();
date.setDisplayValue("2023-06-26 11:00:00");
if (sched.isInSchedule(date))
gs.info("Is in the schedule");
else
gs.info("Is NOT in the schedule");
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2023 09:14 AM
It's weird because this isn't working, either. I tried this in my company instane any my demo instance and it keeps saying it's not in the schedule.
I modified the below for the OOB 8-5 schedule and even this isn't returning true.