Add and remove user to group using catalog item script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-28-2022 11:59 AM
We have 2 catalogs items , one to add users to a group and the other one to remove user from a group with Group manager approval . This was working fine until Management decide to remove direst access to group table. Now when requested the approval part is fine but user(S) is not added or removed to the group. I need assistance adjusting the script. Below is the script
- Labels:
-
HR Service Delivery

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-28-2022 01:40 PM
Hi Gabriel,
Do you have access to view the ACL on the table? Most likely when management removed direct access, they limited the ability of who can maintain group membership via ACL. If this is the case, you will not be able to use your existing code. You'll need access to groups to update the group membership.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-30-2022 08:05 AM
The issue is that the process works for some users but not for all . It seems to me like The scrip need to be updated but I do not where. below is the script :
var groupAddRemoveUtilsHR = Class.create();
groupAddRemoveUtilsHR.prototype = Object.extendsObject(AbstractAjaxProcessor, {
//remove a list of members from the group
removeMembers: function(group,memList){
var memstr = memList.toString();
var impuser = gs.getProperty('SysIDofSystemAdmin');
var myID = gs.getUserID(); //get the ID of the current logged in user
gs.getSession().impersonate(impuser);
var gm = new GlideRecord('sys_user_grmember');
gm.addQuery('group',group);
gm.addQuery('user','IN',memstr);
gm.query();
while(gm.next()) {
gm.deleteRecord();
}
gs.getSession().impersonate(myID);
},
//add a list of users to a group
addMembers: function(group,memList) {
var impuser = gs.getProperty('SysIDofSystemAdmin');
var myID = gs.getUserID(); //get the ID of the current logged in user
gs.getSession().impersonate(impuser);
var memstr = memList.toString();
var memArr = [];
if(memstr.indexOf(',')>-1) {
memArr = memstr.split(',');
} else {
memArr.push(memstr);
}
var msg = '';
for(var i=0;i<memArr.length;i++) {
var gm = new GlideRecord('sys_user_grmember');
gm.initialize();
gm.group = group;
gm.user = memArr[i];
var x = gm.insert();
}
gs.getSession().impersonate(myID);
},
type: 'groupAddRemoveUtilsHR'
});