Before Query Business rule - Need help with Script portion please
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2024 09:32 AM
I have a before Query business rule that I'm using to hide records from everyone unless they have a certain role of sec_research. For security reasons we only want people with this role to see certain record items.
I have the following script:
(function executeRule(current, previous /*null when async*/) {
// Add your code here
if(!gs.getUser().hasRole('sec_research')){
current.addEncodedQuery('short_description!=Email Request Access');
}
})(current, previous);
Currently if they are in the sec_research group they can see the records. That works. However when I look at someone with admin they also see the records. How can I make this so it will not allow Admin's to see those records as well.
If someone could please lend some assistance that would be great.
Requirements on the Business rule as are follows:
1. create a business rule on the sc_task table
2. Set advanced on
3. Select Query and When to Before
4. Go to action tab to set script
I'm not sure I need anything in the condition or not?
Thanks in advance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2024 10:17 AM
Did not work
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2024 11:04 AM
With this approach, you would want to use
if(!isRolePresent){
to add the restriction if the current user does not have this specific role.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2024 11:01 AM
Hi @Community Alums ,
Can you check once in the scripts - background and check what's the output ?
var arrayUtil = new ArrayUtil();
var userRoles = gs.getSession().getRoles() + ''; // get the roles assigned to the user
var roleArray = userRoles.split(",");
var isRolePresent = arrayUtil.contains(roleArray, 'sec_research');
if(isRolePresent){
gs.info('Yes');
}else{
gs.info('No');
}
Output:
*** Script: No
Regards,
Najmuddin.