diff --git a/Server-Side Components/Background Scripts/Get all users where manager is empty/Readme.md b/Server-Side Components/Background Scripts/Get all users where manager is empty/Readme.md new file mode 100644 index 0000000000..05fca3aa37 --- /dev/null +++ b/Server-Side Components/Background Scripts/Get all users where manager is empty/Readme.md @@ -0,0 +1,45 @@ +Users Without Manager - ServiceNow Background Script + +This ServiceNow Background Script fetches all active users who do not have a manager assigned and provides a list of their names along with their Sys IDs, plus the total count of such users. + +Features + +Lists all active users without a manager. + +Displays user display names along with their Sys IDs. + +Provides a total count at the end. + +Fully server-side, runs directly in Background Script. + +Wrapped in a self-invoking function to avoid variable scope issues. + +Usage + +Log in to your ServiceNow instance. + +Navigate to: System Definition → Scripts - Background. +Click Run Script. + +View the output in the System Logs → All (gs.info) to see: + +A list of users without a manager + +Their Sys IDs + +Total count + +Example Output +Users without manager are: +John Doe (Sys ID: 46d1f2f0db123300f0a12345c0a12345) +Jane Smith (Sys ID: 46d1f2f0db123300f0a12345c0a67890) +... +Total users without manager: 42 + +Notes + +This script only fetches active users (active=true). + +You can modify the query to add additional filters if required (e.g., by department or role). + +Ideal for administrators to quickly identify users without assigned managers for audits or reporting purposes. diff --git a/Server-Side Components/Background Scripts/Get all users where manager is empty/Yser where Manager is Empty.js b/Server-Side Components/Background Scripts/Get all users where manager is empty/Yser where Manager is Empty.js new file mode 100644 index 0000000000..757998808d --- /dev/null +++ b/Server-Side Components/Background Scripts/Get all users where manager is empty/Yser where Manager is Empty.js @@ -0,0 +1,18 @@ +(function() { + var users = []; + var userGr = new GlideRecord('sys_user'); // used different variable name instead of gr. + userGr.addActiveQuery(); // only active users + userGr.addNullQuery('manager'); // users with no manager + userGr.query(); + + var count = 0; // Initialize count + + while (userGr.next()) { + // Include Sys ID along with display name + users.push('\n' + userGr.getDisplayValue() + ' (Sys ID: ' + userGr.getUniqueValue() + ')'); + count++; // Increment count + } + + gs.info("Users without manager are: " + users.join('')); + gs.info("Total users without manager: " + count); +})();