Add user to group via workflow

Clinton F
Tera Expert

Hi All,

I just want to know if it is possible and how much effort is required to get the following working.

We have allot of requests for ServiceNow access in our company and we would like to automate this process via a Workflow. I want to create a new RITM and a new Workflow to handle these requests. In the workflow we want to be able to ask the user to tell us which group(s) they need to be a member of, this will provide access to them.

This is the part I am not sure I can do or how we would do it. The rest of the workflow would then go for approval first and once approved I want ServiceNow to add them to those group(s) and then close the Request.

Has anyone done something similar and do you know how much effort will be required, hours / days / weeks etc.

15 REPLIES 15

davidmorgan
Tera Contributor

Copied below is an example function to add a user to a group. As you loop through your users/groups, call this function.

 

var user = ''; // user sys_id

var group = ''; // group sys_id

addUserToGroup(user, group);

 

function addUserToGroup(user, group) {

   var groupGR = new GlideRecord('sys_user_grmember');
   groupGR.initialize();
   groupGR.user = user;
   groupGR.group = group;
   groupGR.insert();

}