- 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 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 01:44 PM
Hello Thank you so much its working fine!! and I need to restrict duplicate users add into the group if you have any resolution, please help me with that. Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-06-2022 02:40 PM
Hello,
Please use below code
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()) // put not condition so that it rescricts the creation of the duplicate record
{
groupQuery.initialize();
groupQuery.user = current.variables.requesting_for;
groupQuery.group = "group_sys_id"; // need to mention sys id of the group
groupQuery.insert();
}
Please mark this helpful if you fond it use ful
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-06-2022 01:35 PM
Hi there!
You have to use "current.variables.variable_name" instead of "current.variable_name".
Regards,
Palak