← Script library

Background Scripts

Report Active Incidents Without Callers

Find up to 100 active incidents with an empty caller reference for manual data-quality review. Read-only; no records or notifications are changed.

JavaScript
(function reportCallerlessIncidents() {
  var prefix = '[SN-Tricks:CallerlessIncidents]';
  var limit = 100;
  try {
    var incidents = new GlideRecord('incident');
    incidents.addQuery('active', true);
    incidents.addNullQuery('caller_id');
    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) without a 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] fields with GlideRecord; no cross-scope access is required in Global. 2. Run and search output for [SN-Tricks:CallerlessIncidents]. Only Active is true and Caller is empty qualify. Rows contain incident number, sys_id, and creation timestamp in UTC, oldest first with sys_id as a tie-breaker. No descriptions or caller personal details are logged. 3. Test active incidents with empty and populated caller_id values and inactive incidents with empty callers. Only active incidents with empty callers should appear. Opened by, assignment group, and assignee do not substitute for Caller and do not affect selection. Compare with an incident list using the same filters and execution/domain context. 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 validation on your ServiceNow instance. 5. An empty caller can be intentional for monitoring or integration-created incidents. Review intake requirements before remediation; never populate callers solely from this report. Nonempty references to deleted or inactive users 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 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.