Background Scripts
Report Overdue Active Tasks
Find up to 100 active tasks whose populated due date is before the execution time, oldest first. Read-only; no records are changed.
(function reportOverdueTasks() {
var prefix = '[SN-Tricks:OverdueTasks]';
var limit = 100;
try {
var cutoff = new GlideDateTime().getValue();
var tasks = new GlideRecord('task');
tasks.addQuery('active', true);
tasks.addNotNullQuery('due_date');
tasks.addQuery('due_date', '<', cutoff);
tasks.orderBy('due_date');
tasks.orderBy('sys_id');
tasks.setLimit(limit + 1);
tasks.query();
var shown = 0;
var truncated = false;
while (tasks.next()) {
if (shown >= limit) {
truncated = true;
break;
}
gs.info(prefix + ' task=' + tasks.getUniqueValue() +
' | number=' + tasks.getValue('number') +
' | due_date_utc=' + tasks.getValue('due_date'));
shown++;
}
gs.info(prefix + ' Cutoff UTC: ' + cutoff + '; reported ' + shown +
' overdue active task(s).' + (truncated
? ' More matches exist; output capped at ' + limit + '.'
: ' All matching tasks shown.'));
} catch (error) {
gs.error(prefix + ' Report failed; disregard partial output: ' + error);
}
})();How to use it
1. As an authorized administrator, open System Definition > Scripts - Background in a non-production instance and select Global scope. Paste the script. This custom diagnostic uses OOB GlideRecord; it does not change task records or send notifications. 2. The task table includes extended task types. Only active records with a populated due_date strictly before a single captured execution timestamp qualify. A due date equal to the cutoff is not overdue. This is not an SLA breach report: schedules, task_sla, and duration calculations are not evaluated. 3. Run and find [SN-Tricks:OverdueTasks] in the output. Rows contain only task sys_id, number, and UTC due date. Results are ordered by due_date and then sys_id, with at most 100 rows; a 101st match signals truncation. The printed count is not a total when capped. 4. Test active tasks with past, future, and empty due dates, and an inactive task with a past due date. Only the active past-due task should appear. Check zero, 100, and 101 matches; compare against a task list with equivalent filters and the exact logged cutoff in the same domain. Account for local-time display when comparing UTC dates. 5. Domain separation, query business rules, and concurrent updates affect visibility and results. Administrative GlideRecord is not an ACL-filtered end-user endpoint. Restrict task identifiers to authorized staff. The row cap does not bound database scan cost; measure performance on representative data before production use. 6. Errors invalidate any partial output. No data rollback or update set is needed for ad hoc execution. Local mock tests do not replace sub-production instance validation; no cross-scope access is required for Global execution.
Adapt the table names, fields, and conditions to your instance. Test the behavior in a development environment before using it in production.