← Script library

Background Scripts

Report Active Groups with Inactive Managers

Find active groups whose referenced manager is inactive, for manual ownership review without changing group membership or manager assignments.

JavaScript
(function reportInactiveGroupManagers() {
  var prefix = '[SN-Tricks:InactiveGroupManagers]';
  var limit = 100;
  try {
    var groups = new GlideRecord('sys_user_group');
    groups.addQuery('active', true);
    groups.addNotNullQuery('manager');
    groups.addQuery('manager.active', false);
    groups.orderBy('sys_id');
    groups.setLimit(limit + 1);
    groups.query();

    var shown = 0;
    var truncated = false;
    while (groups.next()) {
      if (shown >= limit) {
        truncated = true;
        break;
      }
      gs.info(prefix + ' group=' + groups.getUniqueValue() +
        ' manager=' + groups.getValue('manager'));
      shown++;
    }
    gs.info(prefix + ' Reported ' + shown + ' active group(s) with inactive managers.' +
      (truncated ? ' More matches exist; output capped at ' + limit + '.' : ' All matching groups 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. This custom diagnostic uses the OOB sys_user_group table and its manager reference to sys_user. No cross-scope access is required in Global. Keep limit a positive whole number. 2. Run the script and search output or system logs for [SN-Tricks:InactiveGroupManagers]. It filters active groups with a populated manager reference whose active flag is false. Groups without managers, dangling references, and inactive groups are outside this report's purpose. It does not establish whether a group is used for task assignment or approvals. 3. In sub-production, test active groups with an active manager, an inactive manager, and no manager; also test an inactive group with an inactive manager. Only the active group with an inactive manager should appear. Compare with the group list using the same filters and domain context. Use dedicated test records, not real account deactivations. 4. Test zero, exactly 100, and 101 matching groups. Output is ordered by sys_id and capped at 100; an extra fetched row detects truncation. A capped count is not a total. The script logs group and manager IDs only, not names or contact details. Internal identifiers still require appropriate log access. 5. Review each result with the group owner before assigning a replacement. An inactive manager alone does not prove that approvals are stalled, members are inactive, or the group should be deactivated. No replacement is selected automatically. 6. Administrative GlideRecord is not an ACL-filtered end-user report. Domain separation, query business rules, reference visibility, and concurrent changes can affect results. The output cap does not bound database scan or join cost; evaluate runtime against representative data before production use. 7. If an error is logged, disregard partial output. This script performs no inserts, updates, deletes, or notifications, so no data rollback is needed. Ad hoc execution creates no reusable update-set configuration. Local checks do not replace validation on a ServiceNow instance.

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