How to get the Group members Count on the Group table?

sravanthivaina1
Kilo Explorer

Hi All,

I want to store group members count in group table through business rule, please refer below code i have written to get member count on string filed.

Below code is working when group details (i.e. description or any field) updated, so want to modify code without update (or) insert any details on group table, i want to store the count. is it possible if yes, please help.

BR when to run.PNGBR Script.PNG

Thanks,

Sravanthi

7 REPLIES 7

Try below code as example. Change the required fields names.



var gr = new GlideRecord('sys_user_grmember');


gr.addQuery('group',current.group);


gr.query();


var count = gr.getRowCount();


var g1r = new GlideRecord('sys_user_group');


gr1.addQuery('group',current.group);


gr1.query();


if(gr1.count != count){


gr1.count = count;


gr1.update();


}


Hi,




I Have changed the table and code as per below but still its not working.Kindly help me on this.




Thanks,


Sravanthigroup count-post2.pnggroupcount script-post2.png


Dan Covic
Tera Contributor

The question is not clear. Do you mean to query for the number of group members?

If so, please have a look at this article:

Group Member Counts Reports - ServiceNow Guru