how to automate assign user into group through catalog item.

Tharun13
Tera Contributor

Hi All

I have multiple groups and multiple users when user raise request for add into some X two groups, how we write a script in workflow.

how to automate assign user into group through catalog item.

 

Regard,

Tharun

1 ACCEPTED SOLUTION

Hey Tharun,

Update script as below it is working now

var groupsArray = [];
var usersArray = [];
var users = current.variables.user_to_add; //give users list collector variable name
usersArray = users.toString().split(',');
var groups = current.variables.group; //give groups list collector variable name
groupsArray = groups.toString().split(',');

for(var i=0; i<groupsArray.length; i++)
{
for(var j=0; j<usersArray.length; j++)
{
var gr = new GlideRecord('sys_user_grmember');
gr.initialize();
gr.user = usersArray[j]; 
gr.group = groupsArray[i]; 
gr.insert();
}
}

 

Mark as correct and helpful if it solved your query.

Regards,
Sumanth

View solution in original post

17 REPLIES 17

Hi Sumanth,

 

Yes, I am using Users field and Groups field both are list collectors.

 

find_real_file.png

Please share the screenshot of the script in your run script to see if there needs to be any changes.

 

Hi Sumanth,

Please find the below screenshots

find_real_file.png

find_real_file.png

In line num 12 and line num 14,

you need to update the backend values of your two list collector variable names.

Hi Sumanth,

I have gave backed values.

var groups = current.variables.group;
var users = current.variables.user_to_add

 

group

user_to_add

I gave same