Background Scripts
Report Active Groups Without Managers
Identify active groups with an empty manager reference for manual ownership review, without modifying group records or membership.
(function reportMissingGroupManagers() {
var prefix = '[SN-Tricks:MissingGroupManagers]';
var limit = 100;
try {
var groups = new GlideRecord('sys_user_group');
groups.addQuery('active', true);
groups.addNullQuery('manager');
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());
shown++;
}
gs.info(prefix + ' Reported ' + shown + ' active group(s) without 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 reads the OOB sys_user_group table. 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:MissingGroupManagers]. It selects active groups with an empty manager reference. Populated references, including inactive managers and dangling references, are outside this report. It does not determine whether a group is used for assignments or approvals. 3. In sub-production, test active groups with no manager, an active manager, and an inactive manager, plus an inactive group with no manager. Only active groups with no manager should appear. Compare with the group list using the same filters and domain context. Use dedicated test data. 4. Test zero, exactly 100, and 101 matches. Results are ordered by sys_id and capped at 100. One extra fetched row detects truncation; a capped count is not a total. Only group IDs are logged, not names or contact details. Restrict log access appropriately. 5. Review results with the service owner before assigning a manager. An empty manager field can be intentional and does not prove stalled approvals or invalid membership. No replacement is selected automatically. 6. Administrative GlideRecord is not an ACL-filtered end-user report. Domain separation, query business rules, and concurrent changes can affect results. The output cap does not bound database scan cost; evaluate runtime on representative data before production use. 7. If an error is logged, disregard partial output. This script performs no inserts, updates, deletes, or notifications; no data rollback is needed. Ad hoc execution creates no reusable update-set configuration. Local mock 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.