Report on the users with no roles and groups

VojjalaS
Tera Contributor

I need to pull a report of users with no roles and no groups.

9 REPLIES 9

Ankur Bawiskar
Tera Patron
Tera Patron

@VojjalaS 

you can create a client callable script include which is classless and use this script

Then in report filter condition call it like this

SysId [IS ONE OF] javascript: usersWithNoRoleNoGroup();

function usersWithNoRoleNoGroup() {
    var usersWithoutRolesOrGroups = [];
    var userGR = new GlideRecord('sys_user');
    userGR.addActiveQuery(); // Only check active users
    userGR.query();
    while (userGR.next()) {
        // Check for roles associated with the user
        var roleGR = new GlideRecord('sys_user_has_role');
        roleGR.addQuery('user', userGR.sys_id);
        roleGR.query();

        // Check for groups associated with the user
        var groupGR = new GlideRecord('sys_user_grmember');
        groupGR.addQuery('user', userGR.sys_id);
        groupGR.query();

        if (!roleGR.hasNext() && !groupGR.hasNext()) {
            // Add user details to the array if they have no roles and no groups
            usersWithoutRolesOrGroups.push(userGR.getUniqueValue());
        }
    }
    return usersWithoutRolesOrGroups.toString();
}

AnkurBawiskar_2-1745398493615.png

 

 

AnkurBawiskar_3-1745398515713.png

 

 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

This script looks familiar ; )

Good to hybrid a solution and good call out @Ankur Bawiskar 

@VojjalaS 

Hope you are doing good.

Did my reply answer your question?

If my response helped please close the thread by marking appropriate response as correct so that it benefits future readers.

 

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

@VojjalaS 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Sachin Parmar
Tera Contributor

You can put a related list condition, below is an example for roles, you can select "None" in the quantity and then select the related list as roles, same can be done for groups

SachinParmar_0-1745477648967.png