- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-30-2023 11:35 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-31-2023 10:37 PM
Thanks all -
Got this working using below code -
inactiveUserCount: function() {
var arr = [];
var group = new GlideRecord('sys_user_group');
group.addEncodedQuery('active=true^typeNOT LIKEd317d8111b537cd096c5a970f54bcbaf');
group.query();
while (group.next()) {
var group_member = new GlideAggregate('sys_user_grmember');
group_member.addEncodedQuery('group.sys_id=' + group.sys_id);
group_member.query();
var member_count = group_member.getRowCount();
if (member_count > 0) {
var active_member = new GlideAggregate('sys_user_grmember');
active_member.addEncodedQuery('group.sys_id=' + group.sys_id + '^user.active=false');
active_member.query();
var active_member_count = active_member.getRowCount();
if (active_member_count == member_count) {
arr += (group.sys_id + ',');
}
}
}
return arr;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-31-2023 10:02 PM
@Dolly M it is not iterating through all group members records btw.
But let me optimize the code and come back here
ServiceNow Community Rising Star, Class of 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-31-2023 02:19 AM
create a client callable script include which is classless and check this
function getGroups(){
var arr = [];
var groupRec = new GlideRecord("sys_user_grmember");
groupRec.query();
while(groupRec.next()){
var group = groupRec.getValue('group');
var grpMemberGr = new GlideRecord("sys_user_grmember");
grpMemberGr.addQuery("group", group);
grpMemberGr.addQuery('user.active', true);
grpMemberGr.query();
if(!grpMemberGr.hasNext()){
arr.push(groupRec.group.toString());
}
}
return arr.toString();
}
This is how you will call the script include
Report will be on Group table and give this filter condition
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-31-2023 03:40 AM
Hi Ankur,
I ran the report but the server became unresponsive and the page got hanged as we have high no. of data in group member table. Also I don't think there is any convenient way to solve this issue.
Basically, this was a requirement from higher management to see groups which have all members as inactive. But there's a lot that needs to be done at the backend because the query/logic has to be ran against each record in sys_user_grmember.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-31-2023 03:45 AM
possibly the query is taking time.
So you better do it for few records first and then use the complete script.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-31-2023 09:36 PM
Hi Ankur,
For few records it is working fine. But not working for all records.
By any chance can it be done via Database view ?