- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-06-2022 12:40 PM
Hello,
I have to create a workflow for adding user to group or remove user from group automatically after approving RITM and task will create after adding the user to group or remove from group, Based on selection of Add or Remove choice list in the catalog item.
Catalog variables are: 1.Requesting for, 2.choice list (Add/Remove)
please help me with procedure and provide any script for this automation for remove or add user to group based on choice selection
I tried to add user with below script in Run script activity but empty record is added to the group
var groupQuery = new GlideRecord('sys_user_grmember');
groupQuery.initialize();
groupQuery.user = current.variables.requesting_for; //whatever your current user field is
groupQuery.group = "group_sys_id"; // need to mention sys id of the group
groupQuery.insert();
Solved! Go to Solution.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-06-2022 12:58 PM
Hello ,
Please try below script for adding into group
var groupQuery = new GlideRecord('sys_user_grmember');
groupQuery.initialize();
groupQuery.user = current.variables.requesting_for; //whatever your current user field is
groupQuery.group = "group_sys_id"; // need to mention sys id of the group
groupQuery.insert();
For removing from the group
var groupDel= new GlideRecord('sys_user_grmember');
groupDel.addQuery('user',current.variables.requesting_for);
groupDel.groupDel.addQuery('groups','group sys_id'); // need to mention sys id of the group
groupDel.query();
if(groupDel.next())
{
groupDel.deleteRecord();
}
Please accept this solution if it is helpful
thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-06-2022 02:04 PM
Hello
For avoiding duplicate entries you can update your code as below
var groupQuery = new GlideRecord('sys_user_grmember');
groupQuery.addQuery('user', current.variables.requesting_for);
groupQuery.addQuery('group', 'group_sys_id'); // need to mention sys id of the group
groupQuery.query();
if (!groupQuery.next())
{
groupQuery.initialize();
groupQuery.user = current.variables.requesting_for;
groupQuery.group = "group_sys_id"; // need to mention sys id of the group
groupQuery.insert();
}
Regards,
Palak