Add user to group via workflow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-16-2015 01:48 AM
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.
- Labels:
-
Service Mapping
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-16-2015 02:17 AM
Hi Clinton.,
I don't have this script ready but technically its doable. After the approval you have to create a Run Script activity and there you will need to write script to make an entry for user and group to sys_user_grmember table, looping for each group selected by user.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-16-2015 02:34 AM
thanks for this. If you have the script or can get it that would help me out. I will start planning the new workflow now that I know it is possible. Thanks for the reply and information.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-17-2015 12:32 AM
Hi,
If you have group id (sys_id) and user ID (sys_id) you can add it using following script
var gmGr = new GlideRecord('sys_user_grmember');
gmGr.initialize();
gmGr.addQuery('group',groupSysId);
gmGr.addQuery('user',userSysId);
gmGr.query();
if(gmGr.next()){
}else{
gmGr.group = groupSysId;
gmGr.user = userSysId;
gmGr.insert();
}
Thanks,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-23-2016 03:43 PM
I've attempted to do this VIA a workflow run script action.Does anyone know if this is something not permitted to do so from the WF. I wouldn't have thought so, but my script works from background scripts, but will not work from this workflow. Here is my script.
I first tried putting all the script into the Run Script box, but after is was not working, I tried building it into a script include, but that doesn't work either.
On the Catalog Item, there is a reference field to specify the user being added to the group(s), and then a list collector for the groups to be specified.
the reference field is "requested_for" and the list collector is "group_list".
RunScript:
var chk = new GrpMemCheck();
chk.addGroups(current.variables.requested_for,current.variables.groups_list);
Here is my script include "GrpMemCheck" :
var GrpMemCheck = Class.create();
GrpMemCheck.prototype = {
initialize: function() {
},
addGroups : function(user,grouplist) {
var addlist = this._pullGrps(user,grouplist);
this._addMembership(user,addlist);
},
_addMembership : function(user,grouplist) {
for (g=0; g<addlist.length; g++) {
var grp = new GlideRecord('sys_user_grmember');
grp.newRecord();
grp.setValue('group',addlist[g]);
grp.setValue('user',reqfor);
grp.insert();
gs.info("Creating record for " + addlist[g]);
}
},
_pullGrps : function(user,grouplist) {
var add = [];
for (i=0;i<grouplist.length;i++) {
var gr = new GlideRecord('sys_user_grmember');
gr.addEncodedQuery("user=" + user + "^group=" + grouplist[i]);
gr.query();
if (!gr.next())
add.push(grouplist[i]);
return add;
}
},
type: 'GrpMemCheck'
};