Business Rule Conditions - Role baed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2018 12:28 PM
When setting up Business Rules, I have included conditions to allow these to only run when logged in user has specific roles.
1. Business Rule should not run for admin.
2. Business Rule should run for user with multiple roles. Here are some examples of the type of roles Users may have.
a) itil -
Condition: !gs.hasRole("admin") && gs.hasRole("itil")
b) itil and catalog -
Condition: !gs.hasRole("admin") && gs.hasRole("itil") && gs.hasRole("catalog")
c) itil and catalog and sam
Condition: !gs.hasRole("admin") && gs.hasRole("itil") && gs.hasRole("catalog") && gs.hasRole("sam")
The goal is for only one of these business rules to run since these are Query Business Rules. The issue I run into is that for a user with the both roles itil and catalog, both b and c BR will run if I do not modify these conditions to the following.
Here is how I modified BR b for itil and catalog role users to get around this issue:
Condition: !gs.hasRole("admin") && gs.hasRole("itil") && gs.hasRole("catalog") && !gs.hasRole("sam")
Looking for help with a better way to setup the conditions to avoid this issue. My understanding is that gs.hasRole() only looks at one role at a time and not all of the roles in the condition. Is there a way to modify the condition to include multiple roles?
Thanks,
Jahanzeb

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2018 01:35 PM
Hello Jahanzeb,
The issue I believe you are running into isn't an issue with the system as it is just an issue with Bs logic. As it is originally written, any user who meets C with also inherently meet B because they have the same roles in them AND they are evaluated independently of each other. Your workaround is actually the solution I would recommend if you were to continue with your implementation of your requirements.
If you are looking to optimize this query you can also consider having a single BR that doesn't run for admins where you just add to the query based on the roles they have.
Code Sample (untested):
//Make sure the BR condition is set to:
//!gs.hasRole('admin) && gs.getSession().isInteractive()
(function(){
var query = '';
if(gs.hasRole("a")){
query += '^stuff';
}
if(gs.hasRole("b")){
query += '^stuff';
}
if(gs.hasRole("c")){
query += '^stuff';
}
current.addEncodedQuery(query);
}());
As with any on query business rule, I always recommend understanding the impact and limiting any recursive behavior. Make sure this is the path you really want to go.
Hope this helps!