Add/ Remove users to the group

Vinay49
Tera Expert

Hello team,

There is two fields on the form 1) is list type field which is refering to user table 2) is refence field  which is readonly & it contains one default group"XXX".

When users added to the list field, same users will be created in the group which is set as default group on above reference field.

When user removed  from the list, same users will be removed from the group which is set as default group on above reference field.

When user addedd some users  & remove some users, Same users will be addedd&removed from the group which is set as default group on above reference field.

 

How can we acheive this.

 

Thanks in advacne

 

2 REPLIES 2

SebastianKunzke
Kilo Sage
Kilo Sage

Hi Vinay,

I do not understand, why you want to build a form for this. You can just open the group and add the user to the group. Where is the added value to do that in a separate form?

It would be a customizing and you need additional ACLs to avoid, that unrestricted persons can add or remove persons to certain groups. 

 

Yash Agrawal1
Tera Guru

Hello @Vinay

If I understood you Requirement Clearly,You basically have 2 field on the catalog item form

1.User-reference field,Which is pointing to User table

2.Group field- readonly, with a default value "XXX".

Now what you want is,All the users added in "Users" variable should get added as a member on XXX group on catalog item submission.

If this is your requirement, here is the Code for that,i would suggest to use Run Script activity in your workflow.

//For Removing users
var users = current.variables.users; //get all the users
var group = current.variables.group; //get the groups

var grug = new GlideRecord('sys_user_grmember');
grug.addQuery('group',groupID);
grug.addQuery('user.sys_id', 'IN', users);
grug.query();
grug.deleteMultiple();

//Add users
var usersarray = users.toString().split(',');
for(var i=0; i<usersarray.length; i++) 
{
var addingusers = new GlideRecord('sys_user_grmember');
addingusers.addQuery('user', userArr[i]);
addingusers.addQuery('group', groupID);
addingusers.query();// checking is users is already member or not
if(!addingusers.next()) //if not a member already 
{
addingusers.initialize(); // then adding users into group.
addingusers.user = userArr[i];
addingusers.group = groupID;
addingusers.insert();
}
}



 

Please let me know if can help you more.

Also If my answer helps you to solve your query,Please Mark it as CORRECT and HELPFUL.