Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
(function() {
// Purpose: Count how many users hold each licensed role
// Roles: sys_approver, itil, business_stakeholder, admin

var roles = ['sys_approver', 'itil', 'business_stakeholder', 'admin'];

for (var i = 0; i < roles.length; i++) {
var roleName = roles[i];

var ga = new GlideAggregate('sys_user_has_role');
ga.addQuery('role.name', roleName);
ga.addAggregate('COUNT');
ga.query();

if (ga.next()) {
var count = parseInt(ga.getAggregate('COUNT'), 10);
gs.info(roleName + ': ' + count + ' licensed users');
} else {
gs.info(roleName + ': no users found.');
}
}

})();
14 changes: 14 additions & 0 deletions Core ServiceNow APIs/GlideAggregate/LicensedUserCount/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Licensed User Count by Role Using GlideAggregate

# Overview
This script counts how many **licensed users** hold specific ServiceNow roles using the `GlideAggregate` API.
It’s useful for **license compliance**, **role audits**, and **access management reporting**.

The licensed roles analyzed:
- sys_approver
- itil
- business_stakeholder
- admin

# Objective
To provide a simple, fast, and accurate way to count licensed users per role directly at the database level using `GlideAggregate`.
Loading