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 11:38 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2022 05:21 AM
Hi,
you can try below one.
var gr = new GlideRecord('sys_user_role');
gr.addQuery('name','LIKE',vaInputs.group_name);
gr.query();
while (gr.next()) {
var gr2 = new GlideRecord('sys_user_has_role');
gr2.addEncodedQuery(role.name=vaInputs.group_role_to_be_removed);
gr2.deleteRecord();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2022 08:55 PM
Hi,
Its not working
Regards,
Surabhi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2022 01:57 AM
Hi Surbhi,
You can use the code that is mentioned in the below community link.
Remove Role : https://community.servicenow.com/community?id=community_question&sys_id=9c39364edb0d4c181cd8a345ca9619db
Just take this as a reference and then code it as per your need.
- Mark my Answer as CORRECT and HELPFUL if it helps
Thanks & Regards,
Anitha H V
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2022 02:53 AM
Hi Anitha,
Its not working for me, I already refered to that link.
Regards,
Surbhi