isInSchedule not working

e_wilber
Tera Guru

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?

 

  var sched = new GlideSchedule('dde09e971b9b291041c20e91604bcb1d'); // Shift 1
  var schedTime = new GlideDateTime('06/26/2023 10:00:00');

  if(sched.isInSchedule(schedTime)){
    gs.print('y');
  }
  else {
    gs.print('n');
  }
 
e_wilber_0-1687791446017.png

 

6 REPLIES 6

Manmohan K
Tera Sage

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');
}

 

 

 

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.

@e_wilber 

 

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");
}

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.

 

var glide = new GlideRecord('cmn_schedule');
glide.addQuery('sys_id', '08fcd0830a0a0b2600079f56b1adb9ae');
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.print("Is in the schedule");
   else
      gs.print("Is NOT in the schedule");
}