Report to show duplicate group members using a script include?

Frank Furter
Tera Contributor

I am trying to run a simple report to produce a list of users that are in multiple resource groups. I think I am close, but my lack javascript skills (and probably script include config!) is got me stumped. 

 

My script looks like this:

 

function getDupGrpMember (){
	var dupRecord = [];
		var gaDupCheck =new GlideAggregate('sys_user_grmember');
		gaDupCheck.addAggregate('COUNT','user');
		gaDupCheck.addNullQuery('user');
		gaDupCheck.groupBy('user');
		gaDupCheck.addHaving('COUNT','>','1');
		gaDupCheck.query();
		while (gaDupCheck.next()) {
			dupRecord.push (gaDupCheck.getValue('user'));
		}
		return dupRecord;
}

 

I have it in System Definition -> Script Includes, is set to All application scopes, is Active and Client callable with no ACL. 

 

When I go to the report, I try to call it like this:
2.png

 

But as you can see, rather than letting me set the field to "javascript: getDupGrpMember();", it just returns the user names (and they're not just the duplicate members, either). 

 

I saw TechoMonk on Youtube do this with the cmdb table, and I modified it for my needs. 

 

What I expect is the report to return a list of users who are in more than one resource group. Also, I don't have the script updated, but I will need it to only consider groups of type 'pps_resource'. I hadn't figured out yet how to specify this in the script. 

 

Not looking for someone to do it all for me, but can anyone point out the error of my ways?

1 ACCEPTED SOLUTION

martinjanke
Kilo Guru

Hi,

 

you can achieve that without any scripting in a report with a related list condition.

 

Report on the user table (sys_user), with the filter condition as per your requirements, e.g. Active = true. Then add a related list condition "greater than 1" on the table "Groups" with the filter "group.roles is pps_resource"

 

 

martinjanke_1-1682406153736.png

 

View solution in original post

3 REPLIES 3

Saurabh Gupta
Kilo Patron
Kilo Patron

Hi,
You can create a dynamic filter and use that filter in your condition.

 

Creating dynamic JavaScript filters in reports - Support and Troubleshooting (servicenow.com)

 

 


Thanks and Regards,

Saurabh Gupta

martinjanke
Kilo Guru

Hi,

 

you can achieve that without any scripting in a report with a related list condition.

 

Report on the user table (sys_user), with the filter condition as per your requirements, e.g. Active = true. Then add a related list condition "greater than 1" on the table "Groups" with the filter "group.roles is pps_resource"

 

 

martinjanke_1-1682406153736.png

 

Frank Furter
Tera Contributor

WHAAAAAAAAAT

 

LOL. Dang it. I hate reinventing the wheel when a simple solution is right under my nose. I really need to learn/use related lists more. Excellent tip, @martinjanke! Works like a charm. Thanks for taking the time to reply, this is great!