Remove Roles From a Group
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2022 04:08 AM
HI,
How can we remove role from a group using script?
Is there any way we can delete any role from a group based on user input?
Regards,
Surbhi
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2022 04:39 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2022 05:19 AM
Hi,
Can you please check what are the values in input Variables?
They must contain group sys_id and Role sys_id.
If your variables contain name of group and name of role then use below script:
var role = new GlideRecord('sys_group_has_role');
role.addQuery('group.name', vaInputs.grou_name);
role.addQuery('role.name', vaInputs.role_to_be_removed);
role.query();
while(role.next())
{
role.deleteRecord();
}
Thanks,
Anil Lande
Thanks
Anil Lande
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2022 08:52 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2022 09:19 PM
Hi,
Have you tested your topic ? see what are the values of these variables in logs.
Can you please share your complete topic flow?
Thanks,
Anil Lande
Thanks
Anil Lande

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2022 09:40 PM
Also can you please share what are the tables selected in your Input Variables for group and role?
var role = new GlideRecord('sys_group_has_role');
role.addQuery('group', vaInputs.group_name);
role.addQuery('role', vaInputs.group_role_to_be_removed);
role.query();
while(role.next())
{
role.deleteRecord();
}
Thanks,
Anil Lande
Thanks
Anil Lande