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.

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

It worked.  Thanks!

 

-Julio

Goran WitchDoc
ServiceNow Employee
ServiceNow Employee

Hi Julio,

 

Take a look here. Steven done a great job creating this Mini-lab which pretty much does what you are looking for:

 

https://community.servicenow.com/community?id=community_blog&sys_id=3a5da629dbd0dbc01dcaf3231f9619da...

 

//Göran

Thanks, but I still can't get my script to work.  It doesn't add any groups.  This is what I have so far for the run script.

 

var grm = new GlideRecord('sys_user_grmember');


grm.initialize();

grm.group = current.variables.groups + '';

grm.user = current.variables.requested_for;

var groupList = [];

// if we have more than one they will be comma delimited

if (grm.group.indexOf(',') > -1) {

groupList = group.split(',');
grm.insert();
}

else {

groupList.push(grm.group); // only one group
grm.insert();
}

juliochacon23
Tera Expert

This is what I have so far.  I can't get the below code to add the groups to the user in ServiceNow.  Can someone check to see what I am doing incorreclty?

 

var grm = new GlideRecord('sys_user_grmember');


grm.initialize();

grm.groups = current.variables.groups + '';

grm.user = current.variables.requested_for;

var groupList = [];

if (grm.groups.indexOf(',') > -1) {

groupList = grm.groups.split(',');

grm.insert();

}

else {

groupList.push(grm.groups); // only one group

grm.insert();

}

 

Thanks

 

-Julio