Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

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

Aman Kumar S
Kilo Patron

Why are you not using Flow designer, I think that will be much easier and low code way of handling this.

If still looking for workflow, you can follow below article:

How to add multiple users to multiple groups through catalog item.

 

 

Best Regards
Aman Kumar

Hello Aman,

we are not using the flow designer, i am new into flow designer. 

I could see above script is Flow designer script. can please share the workflow script

@Tharun 

Below link is used in BR, will need a lil modification to be run into Run script:

Add users to multiple groups

 

Best Regards
Aman Kumar

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

can you share what script did you start with?

Is user variable a list collector and group variable a reference type?

unless you share what type of variables are those we cannot help

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader