Find duplicate users in two groups

Thomas G
Tera Guru

Hi,

It may sound simple but I can't wrap my head around this one at the moment.


I have two groups and need to find users that are members of both. How can I show those in a report? I guess I should look at sys_user_gr_member table. It is easy to find all users from both groups but how can I find only those that are members of both?

 

Best regards

Thomas

1 ACCEPTED SOLUTION

vikrantsharma
Kilo Guru

Hi Thomas,

 

Can you try Multi-level pivot table.

It gives me a an overview of which user is in which group. Like I have filtered on 3 groups with the below config, it gives me the below result, see if this helps?

 

vikrantsharma_0-1668758111783.png

vikrantsharma_1-1668758220494.png

Sorry, I have scribbled over user and Group names.

 

 

Please make it correct or helpful if this solves or help you with your issue for other to make use it.

Thanks & Regards,
Vikrant Sharma

View solution in original post

10 REPLIES 10

Gunjan Kiratkar
Kilo Patron
Kilo Patron

Hi @Thomas G ,

This requirement seems to be difficult to fulfill with normal reporting. You can make use of performance Analytics and create indicator to collect that information. In that Indicator their is option to write down script and we have to create the logic in that script to get those user list.

For better understanding of PA, read my below blog :-

Performance Analytics : Advance Reporting Tool of ServiceNow 


Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy

Hi Gunjan,

Thanks for your reply. 

Best regards
Thomas

Thomas G
Tera Guru

Would it be possible by calling a Script Include in a report?

Best regards
Thomas

Hi Thomas,

 

Yes that could be a way. 

So if you create a script include (and it needs to be Client callable!), then it could look like this: 

var usersMemberOfTwoGroups = Class.create();
usersMemberOfTwoGroups.prototype = {
    initialize: function() {

    },
    getUsers: function() { //You can also pass the sys_ids here in the function to make it more dynamic, but this is just for example
        var users = [];
        var agg = new GlideAggregate('sys_user_grmember');
        agg.addAggregate('COUNT', 'user');
        agg.orderBy('user');
        agg.addQuery('group', 'sys_id_grp1').addOrCondition('group', 'sys_id_grp2');
        agg.query();
        while (agg.next()) {
            var userCount = agg.getAggregate('COUNT', 'user');
            if (userCount > 1) {
                users.push(agg.getValue('user'));
            }
        }
        return users;
    },
    type: 'usersMemberOfTwoGroups'
};

 

Then you can create a report on the sys_user table with this condition: 

SebastianL_0-1668759284135.png

 


Best regards,
Sebastian Laursen