Skip to content

Commit 223fa3b

Browse files
authored
MemberLessGroups
1 parent e026d5b commit 223fa3b

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
var arr=[]; //empty array that can be used later to capture the group names
2+
var gr = new GlideRecord("sys_user_group");
3+
gr.addActiveQuery();//active query to capture to query through all the active groups
4+
gr.query();
5+
while(gr.next()){
6+
var br= new GlideRecord("sys_user_grmember"); //querying grmember table to validate group's members
7+
br.addQuery("group",gr.sys_id.toString());
8+
br.query();
9+
if(!br.hasNext()){ // if no member then capture the group name in the array
10+
arr.push(gr.name.toString());
11+
}
12+
}
13+
gs.print(arr.join(",")); //printing the array with all the memberless group names
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
This background script captures all the groups which are active and do not have any members added to the group.
2+
3+
What your script does correctly
4+
5+
Queries all active groups from sys_user_group.
6+
7+
For each group, it checks sys_user_grmember to see if there’s at least one member.
8+
9+
If no member exists (!br.next()), it pushes the group name into arr.
10+
11+
Finally, prints all such group names, comma-separated.
12+
13+
So logically, it works fine and will print all active groups with zero members.

0 commit comments

Comments
 (0)