Business Rule Not working When adding roles from Groups
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-28-2018 11:32 PM
Hello,
I have requirement where i have created a custom Checkbox field (i.. ITIL User) on user table (sys_user).
I need to check this field check/uncheck based on role added to user though groups, So i have created a business rule as following:
table : sys_user_has_role
when to run: Before "Insert" & "delete"
Filter condition: Role is "ITIL"
Code:
----------------------------------------------------------------------------
(function executeRule(current, previous /*null when async*/) {
// Add your code here
if(current.operation()=='insert')
{
var usr=new GlideRecord('sys_user');
usr.addQuery('sys_id',current.user);
usr.query();
if(usr.next())
{
usr.u_itil_user=true;
usr.update();
}
}
if(current.operation()=='delete')
{
var usr1=new GlideRecord('sys_user');
usr1.addQuery('sys_id',current.user);
usr1.query();
if(usr1.next())
{
usr1.u_itil_user=false;
usr1.update();
}
}
})(current, previous);
------------------------------
The above is working fine when I'm providing ITIL role directly to user but its working when we are providing roles to users through groups.
Kindly suggest on this.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-15-2020 11:05 PM
Hi Hussain,
The business rule you wrote will only work for roles added directly to the user record. Like Niagarwal mentioned roles added via group do not trigger any business rules. Below are the steps you would need to take to achieve your desired outcome:
1. make the business rule you mentioned after insert/update
2. Include a condition in the delete one where you query to see if the user still has an ITIL role, since he might be given ITIL form multiple groups. So removing him from one group doesn't make him a non-itil if he still has the role from another group.
3. you will have to create another business rule on the group membership table, which will also be an after insert/update rule similar to the one you created, with an added check to see if the group had ITIL role.
Hope this helps. Kindly mark correct or helpful if it did.
Thanks,
Sneha