Find the group who has itil role and group member is empty
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-29-2024 09:30 AM
find the group who has itil role and group member is empty.
I have to find out the Group name which has ITIL ROLE And no group member or group member is empty.
So for that I have written script . but it is not working .
// Define the ITIL roles to check
var itilRoles = ['itil', 'itil_admin'];
// Get all groups
var groups = new GlideRecord('sys_user_group');
groups.query();
// Iterate through each group
while (groups.next()) {
// Check if the group has ITIL roles
var hasItilRoles = true;
for (var i = 0; i < itilRoles.length; i++) {
if (!groups.hasRole(itilRoles[i])) {
hasItilRoles = false;
break;
}
}
// Check if the group has no members
var hasMembers = new GlideRecord('sys_user_grmember');
hasMembers.addQuery('group', groups.sys_id);
hasMembers.query();
if (hasItilRoles && !hasMembers.hasNext()) {
// Print or log the group information
gs.info("Group with ITIL roles and no members: " + groups.name);
}
}
Thanks. Please help me in this.
1 REPLY 1
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-29-2024 11:58 AM
Hi, this post appears to be a duplicate of this one here.
find the group who has itil role and group member ... - ServiceNow Community