Skip to content

Commit 80fea35

Browse files
Licensed User Count by Role Using GlideAggregate (#2505)
* Create SLA Compliance Ratio by Assignment Group This script calculates the SLA breach percentage for each assignment group based on closed incidents in ServiceNow. It leverages GlideAggregate to count both total SLAs and breached SLAs efficiently, providing key SLA performance insights. * Update SLA Compliance Ratio by Assignment Group * Delete Core ServiceNow APIs/GlideAggregate/SLA Compliance Ratio by Assignment Group * Created script.js * Created readme.md * Update script.js * Create licensed_user_count_by_role.js * Create readme.md * Create Weekly_LicensedUser_Access_Revoke_90Days.js * Create readme.md * Delete Server-Side Components/Scheduled Jobs/Licensed User Access Job directory
1 parent 8155a28 commit 80fea35

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
(function() {
2+
// Purpose: Count how many users hold each licensed role
3+
// Roles: sys_approver, itil, business_stakeholder, admin
4+
5+
var roles = ['sys_approver', 'itil', 'business_stakeholder', 'admin'];
6+
7+
for (var i = 0; i < roles.length; i++) {
8+
var roleName = roles[i];
9+
10+
var ga = new GlideAggregate('sys_user_has_role');
11+
ga.addQuery('role.name', roleName);
12+
ga.addAggregate('COUNT');
13+
ga.query();
14+
15+
if (ga.next()) {
16+
var count = parseInt(ga.getAggregate('COUNT'), 10);
17+
gs.info(roleName + ': ' + count + ' licensed users');
18+
} else {
19+
gs.info(roleName + ': no users found.');
20+
}
21+
}
22+
23+
})();
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Licensed User Count by Role Using GlideAggregate
2+
3+
# Overview
4+
This script counts how many **licensed users** hold specific ServiceNow roles using the `GlideAggregate` API.
5+
It’s useful for **license compliance**, **role audits**, and **access management reporting**.
6+
7+
The licensed roles analyzed:
8+
- sys_approver
9+
- itil
10+
- business_stakeholder
11+
- admin
12+
13+
# Objective
14+
To provide a simple, fast, and accurate way to count licensed users per role directly at the database level using `GlideAggregate`.

0 commit comments

Comments
 (0)