- 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 01:47 AM
@Dolly M Please use below code in the script include function to get the sys ids of all the groups with inactive members.
ServiceNow Community Rising Star, Class of 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-31-2023 09:44 PM - edited ‎05-31-2023 09:45 PM
@Dolly M Did you try this code? This code shouldn't take much time for query. Please try once.
ServiceNow Community Rising Star, Class of 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-31-2023 09:47 PM
Yes, addActiveQuery doesn't works for sys_user_grmember as active field is not present on this table.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-31-2023 09:53 PM
@Dolly M oh yes. Please try the below updated code
ServiceNow Community Rising Star, Class of 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-31-2023 10:00 PM
Thanks @jaheerhattiwale - I tried this code but taking lot of time as it will iterate through each record in sys_user_grmember. The system became unresponsive resulting in error message No response from server.
Can it be done via Database view ?