← Script library

Background Scripts

Report Incidents Assigned to Inactive Users

Find up to 100 active incidents assigned to inactive users so administrators can review stale ownership. Reports only; no records are changed.

JavaScript
(function reportInactiveAssignees() {
  var prefix = '[SN-Tricks:InactiveAssignees]';
  var limit = 100;
  try {
    var incidents = new GlideRecord('incident');
    incidents.addQuery('active', true);
    incidents.addNotNullQuery('assigned_to');
    incidents.addQuery('assigned_to.active', false);
    incidents.orderBy('number');
    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 + ' ' + incidents.getValue('number') +
        ' | incident=' + incidents.getUniqueValue() +
        ' | inactive assignee=' + incidents.getValue('assigned_to') +
        ' | group=' + (incidents.getValue('assignment_group') || '(none)'));
      shown++;
    }
    gs.info(prefix + ' Reported ' + shown + ' active incident(s).' +
      (truncated ? ' More matches exist; output capped at ' + limit + '.' : ' All matching incidents shown.'));
  } catch (error) {
    gs.error(prefix + ' Report failed; preceding output may be partial: ' + error);
  }
})();

How to use it

1. In a non-production instance, open System Definition > Scripts - Background as an authorized administrator. Select Global scope. This is a read-only administrative diagnostic, not a reassignment job. 2. Paste and run the script. Find output using [SN-Tricks:InactiveAssignees]. Each row includes the incident number and sys_ids for the incident, inactive assignee, and assignment group. No short descriptions or user names are logged. 3. Test an active incident assigned to an inactive user (included), an active incident assigned to an active user (excluded), an unassigned active incident (excluded), and an inactive incident (excluded). A missing assignment group is displayed as (none). Deleted or unresolved user references are not an inactive-user audit match. 4. Check zero matches and more than 100 matches. At most 100 rows are printed; one extra row detects truncation. The printed count is not the total when truncated. Compare with an incident list filtered to Active is true, Assigned to is not empty, and Assigned to.Active is false in the same domain context. 5. Review ownership manually under your normal change process. The script uses the active flag rather than customized state values and never inserts, updates, or deletes records; no rollback is needed. 6. The dot-walk query can be expensive on large tables despite the output cap. Test runtime before production use. GlideRecord in a background script is not an ACL-filtered end-user report; domain separation and execution context affect visibility. Keep internal identifiers restricted to authorized staff. If an error occurs, disregard partial output.

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