- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-13-2022 11:53 PM
Hi everyone!
I would like to ask your assistance, I have this requirement wherein when a user is placed as a Group Manager it will automatically grant an "approver_user" role. However, I would also like to revert once the user is no longer a Group Manager.
Currently I am using this BR script to assign an "approver_user" role to a user placed as Group Manager. I would like also like to modify this script to remove the "approver_user" role once the user is no longer a Group Manager.
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
var gr = new GlideRecord("sys_user_has_role");
gr.addQuery("user", current.manager);
gr.addQuery("role.name", "approver_user");
gr.query();
if (!gr.hasNext()) {
gr.initialize();
gr.user = current.manager;
gr.setDisplayValue("role", "approver_user");
gr.insert();
}
})(current, previous);
Thank you in advance!! 🙂
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2022 12:10 AM
Hey,
There are multiple ways to achieve this.
1. You can achieve this using flow designer without writing the script. [Highly recommended]
Documentation: https://docs.servicenow.com/bundle/quebec-servicenow-platform/page/administer/flow-designer/concept/...
2. Create an After Update Business rule on the Group table.
When to Run: Manager [changes]
Advance:
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var gr = new GlideRecord("sys_user_has_role");
gr.addQuery("user", previous.manager);
gr.addQuery("role.name", "approver_user");
gr.setLimit(1);
gr.query();
if (gr.next()) {
gr.deleteRecord();
}
})(current, previous);
Hope that helps!
Regards,
Muhammad
Muhammad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2022 11:50 PM
Hope you are doing good.
Did my reply answer your question?
If my response helped please close the thread by marking appropriate response as correct so that it benefits future readers.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2022 05:06 PM
Hi Muhammad,
Thank you for your help on this. It worked as intended! 🙂
Regards,
Sab