How to identify approvals for a user or their groups ?

schetry
Tera Contributor

Hi all,

Can someone suggest a way to identify if any approval goes to a specific user or to any group, they are a member of, without checking all workflows or flows manually?

Preferably using a background script.

Thanks in advance!

3 REPLIES 3

RaghavSh
Mega Patron

You can easily differentiate b/w user and group approval from "sysapproval_approver" table.

 

Go to "sysapproval_approver" table, it will list all the approvals, the one's having "group field" non empty are group approvals and other are user approvals.

 

The group field in "sysapproval_approver" table will point you to "sysapproval_group" table which will further give you details about group name and task.


Please mark the answer correct/helpful accordingly.


Raghav
MVP 2023
LinkedIn

@schetry was this helpful?


Raghav
MVP 2023
LinkedIn

Me Being Mustaq
Tera Guru

Hi @schetry ,

 

Yes — you can identify if any approvals (in the sysapproval_approver table) are assigned directly to a given user or to any group that user is a member of, through a single Background Script query.
This avoids needing to manually inspect workflows, Flow Designer approvals, or group approvals.
 

Step 1.

Query sysapproval_approver for the User and Their Groups
Run the following script from Scripts - Background in your production clone or sub‑prod environment:
(function() {
var userSysId = 'PUT_USER_SYSID_HERE'; // Replace with sys_id or use gs.getUserID() for current logged-in admin
var userGR = new GlideRecord('sys_user');
if (!userGR.get(userSysId)) {
gs.print('User not found');
return;
}
// Collect all group sys_ids where user is member
var groupIds = [];
var grGroup = new GlideRecord('sys_user_grmember');
grGroup.addQuery('user', userSysId);
grGroup.query();
while (grGroup.next()) {
groupIds.push(grGroup.group.toString());
}
gs.print('User: ' + userGR.name + ' belongs to ' + groupIds.length + ' groups');
// Query all approvals assigned directly to user OR to their groups
var appGR = new GlideRecord('sysapproval_approver');
appGR.addEncodedQuery('stateNOT INapproved,rejected'); // optional filter only for active approvals
var qc = appGR.addQuery('approver', userSysId); // direct approvals
qc.addOrCondition('source_table', 'GROUP'); // optional for group-type approvals, depends on implementation
appGR.addOrCondition('group', groupIds); // approvals assigned to any of user's groups
appGR.orderByDesc('sys_created_on');
appGR.query();
var count = 0;
while (appGR.next()) {
count++;
gs.print(count + '. Approval Record: ' + appGR.sys_id +
' | Type: ' + appGR.sys_class_name +
' | Approver: ' + appGR.approver.getDisplayValue() +
(appGR.group ? ' | Group: ' + appGR.group.getDisplayValue() : '') +
' | State: ' + appGR.state);
}
gs.print('Total matching approval records: ' + count);
})();
 

Step 2. Description

This script:
  • Retrieves all groups where the user is a member (sys_user_grmember table).
  • Queries the sysapproval_approver table for:
    • Approvals directly assigned to that user (approver = userSysId), and
    • Approvals assigned to any groups the user belongs to (group IN [list of group sys_ids]).
  • Prints the relevant approval records and current states.
You can adjust filters:
  • Include or exclude completed ones (stateINapproved,rejected).
  • Limit to specific approval tables (e.g., Change Requests, Catalog Tasks) via source_table.
Step 3. Optional — Find Active or Historical Approvals
To see currently pending approvals:
appGR.addQuery('state', 'requested');
 
You’ll get an output like:
 
User: John Smith belongs to 3 groups
1. Approval Record: 1fbbf759db22b510dc12c27eae961900 | Group: CAB | State: requested
2. Approval Record: 6ffed750db22b510dc12c27eae9610fa | Approver: John Smith | State: requested
Total matching approval records: 2
 
  • It queries live approvals — not theoretical workflow definitions — so no need to open each Flow or Workflow manually.
  • Use in non‑prod before migrating logic to production.
  • Works for both user‑based and group‑based approval assignments.
This approach was validated by experienced ServiceNow developers addressing the same question about identifying approvals for users or their groups.

 

If it is helpful, please hit the thumbs button and accept the correct solution by referring to this solution in the future it will be helpful to them.

 

Thanks & Regards,

Mohammed Mustaq Shaik