Comment
Devarsh Ganesh
Tera Contributor

Please go though the below code.

var count=0;//to count how many groups are not having the members

var countpm=0;//to count how many groups are  having the members

var group_name=[];

var group =new GlideRecord('sys_user_group');

group.query();

while(group.next())

{

    var grm=new GlideRecord('sys_user_grmember');

    grm.addQuery('group',group.sys_id);

    grm.query();

    if(grm.next())

    {

    countpm=countpm+1;

    }

    else

    {

   // gs.print("Member not present:"+group.name);

    group_name.push(group.name.toString());// You can store sys_id also but you have to convert it to string because the array stores string values

    count=count+1;

    }

}

gs.print('No members'+count);

gs.print("groups with no members");

for(var i=0;i<count;i++)

{

 gs.info(group_name[i]);

}

 

 

If it is helpful for you then please give a comment and let me know