Request Catalog Item to add assignment group in ServiceNow

juliochacon23
Tera Expert

Hi, I am currently creating a catalog request to have our users request access to a ServiceNow assignment group through a form on the catalog and add this to their ServiceNow user account.  I don't know what activity I can use in a workflow to automate this.  We currently have Orchestration enabled.  What would be the best way to accomplish this?

 

Thanks

-Julio

1 ACCEPTED SOLUTION

Try this

 

var grpArr = current.variables.groups.toString().split(',');

 

for (var i=0;i<grpArr.length;i++)

{

var grm = new GlideRecord('sys_user_grmember');


grm.addQuery('group',grpArr[i]);

grm.addQuery('user',current.variables.requested_for);

grm.query();

if (!grm.next())

{

grm.group =grpArr[i];

grm.user = current.variables.requested_for;

grm.insert();

}

}


Please mark this response as correct or helpful if it assisted you with your question.

View solution in original post

13 REPLIES 13

SanjivMeher
Kilo Patron
Kilo Patron

You dont need orchestration for this.

You just need a Run Script activity in the workflow to add a record to sys_user_grmember table.


Please mark this response as correct or helpful if it assisted you with your question.

Thanks, I am not good at javascript and not sure how to start.  Any tips or help?

Lets assume group is the variable for group and user is the variable to add user to the group.

both are reference field.

 

Then use Run script as below in the workflow

 

var grm = new GlideRecord('sys_user_grmember');

grm.initialize();

grm.group = current.variables.group;

grm.user = current.variables.user;

grm.insert();


Please mark this response as correct or helpful if it assisted you with your question.

Thanks, this was very helpful the only issue that I have is that it's only assigning the first assignment group.  For the variable group I am using a list collector for type.  When multiple groups are selected only the first group gets assigned to the users accounts.  How can I modify the code to accept multiple groups?

Thank you for your help on this!

 

-Julio