Skip to content

Commit 80711e7

Browse files
authored
Get Groups with no Members.js
The purpose of this script is to identify and list all active user groups that do not have any members. This can be useful for maintaining user group data, identifying orphaned groups, or cleaning up unnecessary entries.
1 parent b168e97 commit 80711e7

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
var myGroups = [];
2+
var grGroup = new GlideRecord("sys_user_group");
3+
grGroup.addActiveQuery();
4+
grGroup.query();
5+
while (grGroup.next()) {
6+
var gaGroupMember = new GlideAggregate("sys_user_grmember");
7+
gaGroupMember.addQuery("group",grGroup.sys_id.toString());
8+
gaGroupMember.addAggregate('COUNT');
9+
gaGroupMember.query();
10+
var gm = 0;
11+
if (gaGroupMember.next()) {
12+
gm = gaGroupMember.getAggregate('COUNT');
13+
if (gm == 0)
14+
myGroups.push(grGroup.name.toString());
15+
}
16+
}
17+
gs.print(myGroups);

0 commit comments

Comments
 (0)