Finding Incidents Outside of a Schedule

Here is some code you can use to find incidents outside a certain schedule.  In this example, it finds overnight incidents against a schedule, but you can adjust this code to meet your needs as well:

Script Include: findOvernightIncidents

Client Callable: true
function findOvernightIncidents() {
var schedRec = new GlideRecord('cmn_schedule');
schedRec.get('name', '8-5 weekdays excluding holidays');
//ServiceNow Version check for schedules
gs.log('Schedule Found: '+
if (typeof GlideSchedule != 'undefined') {
var sched = new GlideSchedule(schedRec.sys_id);
//gs.log('New Script Include Used: GlideSchedule')
var sched = new;
//gs.log('Old Package Used:')
//Find Incidents in Schedule
var incidents = [];
var grIncident = new GlideRecord('incident');
//gs.log('grIncident Query: ' + grIncident.getEncodedQuery() + ' = ' + grIncident.getRowCount());
while ({
var opened_at = new GlideDateTime(grIncident.opened_at.getDisplayValue());
gs.log('Incident Number: '+grIncident.number+' Opened at: '+grIncident.opened_at.getDisplayValue() +'is in schedule? '+sched.isInSchedule(opened_at));
if (sched.isInSchedule(opened_at) == true) {
gs.log('Incidents Outside of Schedule Yesterday: '+incidents);
return incidents;

Report: Overnight Incidents

Table: Incident
Filter: Number is javascript:findOvernightIncidents()