Skip to content
Release: Australia · Updated: 2026-03-12 · Official documentation · View source

GlideSchedule- Scoped

The scoped GlideSchedule API provides methods for performing operations on GlideSchedule objects, such as adding new schedule segments to a schedule, determining if a date/time is within the schedule, or setting the schedule timezone.

Parent Topic:Server API reference

GlideSchedule - GlideSchedule()

Instantiates an empty GlideSchedule object.

NameTypeDescription
None  

GlideSchedule - GlideSchedule(String sysID, String timeZone)

Instantiates a GlideSchedule object and loads the schedule information. If a time zone is not specified, the current session time zone is used.

NameTypeDescription
sysIDStringThe system ID for the schedule.
timeZoneString

Optional. The time zone to use.Default: The current session time zone.

Time zones can be provided in the following formats.

  • Country/City. For example, America/Los_Angeles.
  • Country/Time zone. For example, US/Pacific.
  • Time zone abbreviation. For example, PST.

For a complete list of valid timezones, see the Time zone field in the User [sys_user] table. For more information about time zones, see Time zones.

var schedule = new GlideSchedule('090eecae0a0a0b260077e1dfa71da828', 'US/Pacific');

GlideSchedule - add(GlideDateTime startDate, GlideDuration offSet)

Adds a new schedule segment to the current schedule.

NameTypeDescription
startDateGlideDateTimeThe starting date of the new schedule segment.
offSetGlideDurationThe time offset of the new schedule segment.
TypeDescription
GlideDateTimeThe schedule updated with the new schedule segment.
var startDate = new GlideDateTime('2014-01-02');
var days = 2;
var dur = new GlideDuration(60 * 60 * 24 * 1000 * days);
var schedule = new GlideSchedule();
var end = schedule.add(startDate, dur);
gs.info(end);

Output:

2014-01-04 00:00:00

GlideSchedule - duration(GlideDateTime startDate, GlideDateTime endDate)

Determines the elapsed time in the schedule between two date time values using the timezone of the schedule or, if that is not specified, the timezone of the session.

NameTypeDescription
startDateGlideDateTimeThe starting datetime.
endDateGlideDateTimeThe ending datetime.
TypeDescription
GlideDurationThe difference between the starting and ending datetime.
var startDate = new GlideDateTime('2014-10-16 02:00:00');
var endDate = new GlideDateTime('2014-10-18 04:00:00');
var schedule = new GlideSchedule();

schedule.load('090eecae0a0a0b260077e1dfa71da828'); // loads "8-5 weekdays excluding holidays" schedule
var duration = schedule.duration(startDate, endDate);
gs.info(duration.getDurationValue()); // gets the elapsed time in schedule

GlideSchedule - getName()

Retrieves the schedule name.

NameTypeDescription
None  
TypeDescription
StringThe name of the current schedule.
sys_id ='04e664654a36232701a2247dcd8fc4cf'; // sys_id for "Application" schedule record
var sched = new GlideSchedule(sys_id);
gs.info(sched.getName());

GlideSchedule - isInSchedule(GlideDateTime time)

Determines if the specified date and time is within the current schedule.

NameTypeDescription
timeGlideDateTimeDate and time value to check.
TypeDescription
BooleanFlag that indicates whether the specified date and time is within the schedule.Valid values: - true: Date and time is within the schedule. - false: Date and time are outside of the schedule.
var glide = new GlideRecord('cmn_schedule');
glide.addQuery('type', 'blackout');
glide.query();
if (glide.next()) {
   var sched = new GlideSchedule(glide.sys_id);
   var date = new GlideDateTime();
   date.setDisplayValue("2007-09-18 12:00:00");
   if (sched.isInSchedule(date)) 
      gs.info("Is in the schedule");
   else
      gs.info("Is NOT in the schedule");
}

GlideSchedule - isValid()

Determines if the current schedule is valid. A schedule is valid if it has at least one schedule span.

TypeDescription
BooleanTrue if the schedule is valid.
var glide = new GlideRecord('cmn_schedule');
glide.addQuery('type', 'blackout');
glide.query();
if (glide.next()) {
   var sched = new GlideSchedule(glide.sys_id);
   var date = new GlideDateTime();
   date.setDisplayValue("2007-09-18 12:00:00");
   if (sched.isValid()) 
      gs.info("Is valid");

   else
      gs.info("Is not valid");
}

GlideSchedule - load(String sysID, String timeZone, String excludeSpanID)

Loads a schedule with the schedule information.

NameTypeDescription
sysIDStringThe system ID of the schedule.
timeZoneString(Optional) The timezone. If a timezone is not specified, or is nil, the current session timezone is used for the schedule.
excludeSpanIDStringAny span to exclude.
TypeDescription
void 
var x = new GlideSchedule();
x.load('08fcd0830a0a0b2600079f56b1adb9ae');

GlideSchedule - setTimeZone(String timeZone)

Sets the timezone for the current schedule.

NameTypeDescription
timeZoneString

The time zone to use.Time zones can be provided in the following formats.

  • Country/City. For example, America/Los_Angeles.
  • Country/Time zone. For example, US/Pacific.
  • Time zone abbreviation. For example, PST.

For a complete list of valid timezones, see the Time zone field in the User [sys_user] table. For more information about time zones, see Time zones.

TypeDescription
void 

This example sets the timezone for the schedule to US/Pacific.

var schedule = new GlideSchedule();
schedule.setTimeZone('US/Pacific');

GlideSchedule - whenNext(GlideDateTime time, String timeZone)

Determines how much time (in milliseconds) until start time of the next schedule item.

This function is intended to be called when the GlideSchedule object (cmn_schedule table) is not currently in the schedule window. The whenNext() call returns duration (in ms) until the GlideSchedule object is within the schedule. This function does not return a meaningful value if called when the GlideSchedule object is within the schedule.

NameTypeDescription
timeGlideDateTimeTime to be evaluated
timeZoneStringTimezone
TypeDescription
NumberNumber of milliseconds until the start time of the next schedule item. Returns -1 if never.
var startDate = new GlideDateTime('2014-10-25 08:00:00');
var glideSchedule = new GlideSchedule('08fcd0830a0a0b2600079f56b1adb9ae', 'UTC');
gs.info(glideSchedule.whenNext(startDate));

Output:

172800000
testScript(); 
function testScript() { 
var now = new GlideDateTime(); //current date and time
var sched = new GlideSchedule("<sys_id>"); // Use a cmn_schedule sys_id 
if (sched.isInSchedule(now)){ 
gs.info('We are in an active schedule window so whenNext() is not helpful'); 
} else{  
gs.info('Not currently in schedule so call whenNext()'); 
var msUntilNext = sched.whenNext(new GlideDateTime(), 'US/Pacific'); 
gs.info('Next schedule starts in '+msUntilNext+' milliseconds'); 
} 
}
\\ Output [schedule inactive)]:
\\ *** Script: Not currently in schedule so call whenNext() 
\\ *** Script: Next schedule starts in -1 milliseconds

Output:

[Scheduled for future] *** Script: Not currently in schedule *** Script: Next schedule starts in 332894000 milliseconds