diff --git a/Server-Side Components/Background Scripts/MemberLessGroups/ReadME.md b/Server-Side Components/Background Scripts/MemberLessGroups/ReadME.md new file mode 100644 index 0000000000..26fcd0c130 --- /dev/null +++ b/Server-Side Components/Background Scripts/MemberLessGroups/ReadME.md @@ -0,0 +1,13 @@ +This background script captures all the groups which are active and do not have any members added to the group. + +What your script does correctly + +Queries all active groups from sys_user_group. + +For each group, it checks sys_user_grmember to see if there’s at least one member. + +If no member exists (!br.next()), it pushes the group name into arr. + +Finally, prints all such group names, comma-separated. + +So logically, it works fine and will print all active groups with zero members. \ No newline at end of file diff --git a/Server-Side Components/Background Scripts/MemberLessGroups/memberlessgroups.js b/Server-Side Components/Background Scripts/MemberLessGroups/memberlessgroups.js new file mode 100644 index 0000000000..5aa39debab --- /dev/null +++ b/Server-Side Components/Background Scripts/MemberLessGroups/memberlessgroups.js @@ -0,0 +1,13 @@ +var arr=[]; //empty array that can be used later to capture the group names +var gr = new GlideRecord("sys_user_group"); +gr.addActiveQuery();//active query to capture to query through all the active groups +gr.query(); +while(gr.next()){ + var br= new GlideRecord("sys_user_grmember"); //querying grmember table to validate group's members + br.addQuery("group",gr.sys_id.toString()); + br.query(); + if(!br.hasNext()){ // if no member then capture the group name in the array + arr.push(gr.name.toString()); + } +} +gs.print(arr.join(",")); //printing the array with all the memberless group names