Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Find the group who has itil role and group member is empty

Raj12341
Tera Contributor

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

Tony Chatfield1
Kilo Patron

Hi, this post appears to be a duplicate of this one here.
find the group who has itil role and group member ... - ServiceNow Community