File tree Expand file tree Collapse file tree 2 files changed +26
-0
lines changed
Server-Side Components/Background Scripts Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 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.
You can’t perform that action at this time.
0 commit comments