← Script library

Background Scripts

Report Active Incidents With Inactive Callers

Find up to 100 active incidents whose caller user record is inactive for manual review. Read-only; no records or notifications are changed.

JavaScript
(function reportInactiveCallerIncidents() {
  var prefix = '[SN-Tricks:InactiveCallerIncidents]';
  var limit = 100;
  try {
    var incidents = new GlideRecord('incident');
    incidents.addQuery('active', true);
    incidents.addQuery('caller_id.active', false);
    incidents.orderBy('sys_created_on');
    incidents.orderBy('sys_id');
    incidents.setLimit(limit + 1);
    incidents.query();

    var shown = 0;
    var truncated = false;
    while (incidents.next()) {
      if (shown >= limit) {
        truncated = true;
        break;
      }
      gs.info(prefix + ' incident=' + incidents.getValue('number') +
        ' sys_id=' + incidents.getUniqueValue() +
        ' created=' + incidents.getValue('sys_created_on'));
      shown++;
    }
    gs.info(prefix + ' Reported ' + shown + ' active incident(s) with an inactive caller.' +
      (truncated ? ' More matches exist; output capped at ' + limit + '.' : ' All matching incidents 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 sub-production instance and select Global scope. This custom diagnostic reads OOB Incident [incident] and its Caller [sys_user] reference with GlideRecord. No cross-scope access is required in Global. 2. Run and search output for [SN-Tricks:InactiveCallerIncidents]. Only incidents where Active is true and the referenced Caller user has Active set to false qualify. Rows contain incident number, sys_id, and creation timestamp in UTC, oldest first with sys_id as a tie-breaker. No caller names, emails, or incident descriptions are logged. 3. Test active incidents with active and inactive callers, inactive incidents with inactive callers, empty caller references, and references to deleted users. Only active incidents pointing to existing inactive users should appear. Compare with an incident list using Active is true and Caller.Active is false in the same execution/domain context. Empty or dangling references are outside this report's scope. 4. Test zero, exactly 100, and 101 matches. At most 100 records are printed; one extra row detects truncation. The reported count is not the complete total when capped. Keep limit a positive whole number. Local mock tests do not replace instance validation, particularly reference-query behavior. 5. An inactive caller may reflect a departed employee or intentional account deactivation. Review incident ownership and communication requirements; do not reactivate users, change callers, or close incidents solely on this report. Locked out users who remain active are outside its scope. 6. Administrative GlideRecord is not an ACL-filtered end-user report. Domain separation, query business rules, and concurrent updates can affect results. Restrict identifiers and logs to authorized staff. The row cap limits output, not database scan or reference join cost; measure runtime on representative data before production use. 7. If any error is logged, disregard partial output. The script performs no inserts, updates, deletes, or notifications, so no data rollback is needed. Ad hoc execution creates no reusable configuration to capture in an update set.

Adapt the table names, fields, and conditions to your instance. Test the behavior in a development environment before using it in production.