diff --git a/Core ServiceNow APIs/GlideAggregate/LicensedUserCount/licensed_user_count_by_role.js b/Core ServiceNow APIs/GlideAggregate/LicensedUserCount/licensed_user_count_by_role.js new file mode 100644 index 0000000000..180942c820 --- /dev/null +++ b/Core ServiceNow APIs/GlideAggregate/LicensedUserCount/licensed_user_count_by_role.js @@ -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.'); + } + } + +})(); diff --git a/Core ServiceNow APIs/GlideAggregate/LicensedUserCount/readme.md b/Core ServiceNow APIs/GlideAggregate/LicensedUserCount/readme.md new file mode 100644 index 0000000000..d5617f2bc2 --- /dev/null +++ b/Core ServiceNow APIs/GlideAggregate/LicensedUserCount/readme.md @@ -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`.