Create a new catalog item to manage Group Membership
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-09-2022 09:55 AM
Hi,
My client wants to manage the group membership (add or remove a member from a group).
So, I am proposing a catalog item to do this job.
Do we have any OOB catalog item for that?
If we do not, then can I get the script to be used in the workflow of the catalog item to do this job.
Please help.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-09-2022 10:01 AM
There isn't a catalog item/workflow OOTB.
You can probably easily create a flow instead of a workflow, but if you want a workflow script, the solution posted here should work: https://www.servicenow.com/community/it-service-management-forum/add-remove-users-to-the-group/m-p/5...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-09-2022 10:18 AM
@Mike_R - Thank you. Let me check this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-09-2022 10:22 AM
Hello Karthick
You need to create a catalog this with field like group that you need to modify and the user that you need to remove or add to the group
you can use following script for removing / add (make changes accordingly)
Note :- this is not a tested script.. please test it before implementing
function removeGroupsOfInactiveUser() {
var groupGR = new GlideRecord(‘sys_user_grmember’);
groupGR.addQuery(‘user’, current.u_employee_name);
groupGR.query();
while (groupGR.next()) {
groupGR.deleteRecord();
}
}
function removeRolesOfInactiveUser() {
var roleGR = new GlideRecord(‘sys_user_has_role’);
roleGR.addQuery(‘user’, current.u_employee_name);
roleGR.query();
while (roleGR.next()) {
roleGR.deleteRecord();
}
}
like wise assuming it would be multiple that you need to use for loop
var user = current.variables.<field name>;
var group = current.variables.<group field name>; //get the groups
var users = user.toString().split(',');
for(var i=0; i<users.length; i++)
{
var userGR = new GlideRecord('sys_user_grmember');
userGR.addQuery('user', users[i]);
userGR.addQuery('group', group);
userGR.query();
if(!userGR.next())
{
userGR.initialize();
userGR.user = users[i];
userGR.group = group;
userGR.insert();
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-09-2022 10:24 AM
Thanks @rajesh9885 . Will check on this as well.