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

You can do something like this

 

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

 

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

{

var grm = new GlideRecord('sys_user_grmember');


grm.initialize();

grm.groups =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.

Thanks, this almost worked.  When I add groups they show up empty on the users profile.  Any ideas?  I can see that 3 groups are added to the users account but the names are blank for each group.

 

Thanks

-Julio

correction to the script

 

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

 

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

{

var grm = new GlideRecord('sys_user_grmember');


grm.initialize();

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.

Awesome this worked.  The only issue I have now is if the user already has the group and they request it again, this adds the group twice.  How do I check if they have the group already added?

 

Thanks

-Julio

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.