- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-30-2014 11:12 AM
How to reference current record fields in an encoded query for a Before/Query business rule
We would be to use a Before/Query business rule that would filter the records based on the user's role. We can do this from an ACL but this is problematic, because most records will be blocked by the ACL and will result in only a couple of records on each of the list pages. Each page will include a "Number of rows removed from this list by Security constraints" message, where the user must page forward through many screens to find the few records that they need to access.
There does not seem to be a way to build the query based on a value in the "current" record object. The "current" record object can be accessed in the ACL script, but it
cannot be accessed from the script in the before Before/Query business rule.
For example:
Assume that a record has a field titled "Role"
How do you build a query string such as gs.hasRole(current.role)?
This will work in the ACL, but there does not appear to be a way to get it into an encoded record query for the Before/Query business rule.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2014 12:45 PM
Hi @Robert Barnes
Thanks for clarifying your question.
Since you would like to make roles dynamic I would use a function to find all the roles and adding it into the query.
Following is something that can be done:
var encodedQuery = '';
var userRoles = _getLoggedInUserRoles();
encodedQuery = encodedQuery + '^ORrolesCONTAINS'+userRoles;
current.addEncodedQuery(encodedQuery);
function _getLoggedInUserRoles(){
userRoles = [];
var grHasRole = new GlideRecord('sys_user_has_role');
grHasRole.addQuery('user',gs.getUserID());
grHasRole.query();
while(grHasRole.next()) {
userRoles.push(grHasRole.role.name);
}
return userRoles;
}
I hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-08-2017 02:00 AM
HI Brajendra,
I too have similar requirement. But the issue, I am facing is, it is overriding module level filters instead of adding. Please let me know if there is any way to achieve this.