Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Restrict HR Case by Assignment Group UNLESS Opened For

lawrencemgann
Tera Guru

Hello,

 

I have a business requirement to restrict visibility of cases in payroll groups to only members of those groups.  Easy enough -- where I'm running into trouble is making sure the cases are still visible for the employee Opened_For.

 

I started by writing the below script,

 

 

(function executeRule(current, previous /*null when async*/) {
	
	var currentUser = gs.getUser();
	
	var isMemberAPAC1 = currentUser.isMemberOf('043b5d3e475ddd18fe88645f746d436f'); // HR Payroll APAC 1
	var isMemberAPAC2 = currentUser.isMemberOf('9e3bddfe475ddd18fe88645f746d4375'); // HR Payroll APAC 2
	var isMemberAPAC3 = currentUser.isMemberOf('5240a214471fdd50fe88645f746d435e'); // HR Payroll APAC 3

	

	if(isMemberAPAC1 == false) {
		current.addQuery('assignment_group', '!=', '043b5d3e475ddd18fe88645f746d436f'); //HR Payroll APAC 1
	}
	if(isMemberAPAC2 == false) {
		current.addQuery('assignment_group', '!=', '9e3bddfe475ddd18fe88645f746d4375'); //HR Payroll APAC 2
	}
	if(isMemberAPAC3 == false) {
		current.addQuery('assignment_group', '!=', '5240a214471fdd50fe88645f746d435e'); //HR Payroll APAC 3
	}



})(current, previous);

 

 

but I'm not sure how to exempt/modify the query so cases where

 

currentUser = case.opened_for

 

are not hidden.  Has anyone encountered a scenario like this?  Any help is appreciated!

 

 

1 ACCEPTED SOLUTION

lawrencemgann
Tera Guru

Marking this as resolved -- I found the solution and it involved rethinking the and/or statement and using an encoded query!

View solution in original post

2 REPLIES 2

lawrencemgann
Tera Guru

Marking this as resolved -- I found the solution and it involved rethinking the and/or statement and using an encoded query!

Dhanaja Rode
Tera Contributor

Hi @lawrencemgann 

Can you please provide the whole Solution