Display Business Rule - Limit visibility unless you are the submitter

mgaston
Tera Contributor

Hello ServiceNow Gang,

 

I have been wrestling with this one for quite a bit, it doesn't seem like a hard task but it has me stuck. I'm trying to create a display business rule to restrict visibility of incidents that are assigned to a certain group. I've been able to do this no problem, but the issue is I want the incidents assigned to this group to be visible, if you are the one that submitted it. So you'll be able to see the incidents you created, but no other incidents that are assigned to that group. Any help would be much appreciated.  

3 REPLIES 3

Community Alums
Not applicable

you can use a Display Business Rule: 

 

(function executeRule(current, previous /*null when async*/) {

// Define the group to restrict visibility (replace 'YOUR_GROUP_SYS_ID' with the actual Group Sys ID)
var restrictedGroupSysId = 'YOUR_GROUP_SYS_ID';
// Check if the incident is assigned to the restricted group
if (current.assignment_group == restrictedGroupSysId) {

// Check if the current user is not the caller of the incident
if (current.caller_id != gs.getUserID()) {
// Add the current user to the ACL (Access Control List) for visibility
current.addEncodedQuery('caller_id=' + gs.getUserID() + '^ORassignment_group=' + restrictedGroupSysId);
}
}

})(current, previous);

 

 

Anirudh Pathak
Mega Sage

Hi @mgaston ,

Please try below code - 

 

var user = gs.getUserName();
if (gs.getUser().isMemberOf('YourGroupName')) { 
     return;
} /* Return all the incidents if they are part of the group, you can put the logic here based 
       on your requirement
   */

current.addQuery('assignment_group', 'YourGroupSysID');
current.addQuery('sys_created_by', user);

/*Above two lines will make sure if the user is not part of the group but that user has created the incident 
where assignment group is the restricted assignment group then the user will be able to 
 see those incidents
*/

 

 

Hello, 

This does work in restricting visibility for the other tickets in the group, however now they are only able to see these tickets and none others in the instance.