Before Query Business rule - Need help with Script portion please

Community Alums
Not applicable

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

7 REPLIES 7

Community Alums
Not applicable

Did not work

With this approach, you would want to use

	if(!isRolePresent){

to add the restriction if the current user does not have this specific role.

Hi @Community Alums ,
Can you check once in the scripts - background and check what's the output ?


NajmuddinMohd_0-1731524400548.png

 

 

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.