- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2023 09:36 AM - edited 04-24-2023 10:10 AM
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:
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?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2023 12:03 AM
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"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2023 10:23 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2023 12:03 AM
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"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2023 04:44 AM
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!