How to restrict to add users in a group when count will be more than 50 by system property

Amol Pawar
Tera Guru

Hi All,

I need help with the below scenario:

 

We have created a group. When someone raises a request from a record producer, we add that user to that group which has a itil role. We want to restrict adding users to that group when the group members count is more than 50.

How can we achieve this?

The requirement is that achieve this by a system property, but let me know if is there any way we can do this.

 

Thanks in advance,

Amol

6 REPLIES 6

Anil Lande
Kilo Patron

Hi,

You can use before insert BR on sys_user_grmember table.

In your BR you can use script like below:

var maxCount = gs.getProperty('propertyName');
var grMem = new GlideRecord('sys_user_grmember');
grMem.addQuery('group',current.group);
grMem.query();
if(grMem.getRowCount()>maxCount){
gs.addErrorMessage('This group has reached maximum member count '+maxCount);
current.setAbortAction(true);
}
Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

sushantmalsure
Mega Sage
Mega Sage

Hi @Amol Pawar 

You can write before insert BR on table Group Member (sys_user_grmember) which can restrict the group member addition referencing to your system property value.

Script for BR can be:

if(current.group.name=='<enter correct group name>')
{
var getCount = new GlideRecord('sys_user_grmember');
getCount.addQuery('group.name',current.group.name);
getCount.query();
if(getCount.getRowCount() >= gs.getProperty('specify_property_name'))//make sure type of property is integer
{
current.setAbortAction(true);
}
}

 

 

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Regards,Sushant Malsure

Amol Pawar
Tera Guru

Hi @sushantmalsure and @Anil Lande ,

Thank you for your reply.

 

My scenario is through the service portal when an end user creates a request, it will seek approval. When the approver approves that request, the requestor will get added to that group. It's configured in a workflow. I've created one run script in the workflow to add the requestor in that group when the approver approves his request.

And now, I want to restrict adding members to that group when n number of limits is reached. Shall I edit the run script in the workflow itself or Business rule and system property will work?

I've edited the run script and it's not adding members to that group but as per the next activity of workflow, it's sending an email to the user that you've added to that group even if that person is not added to that group.

 

Thanks and regards,

Amol

 

Hi,

You have to manage it in your script and track who all are added and send email to those users only. Not sure if you are sending generic email to all selected users.

You can use workflow scratchpad variables to store error and users who are added into the group.

 

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande