case visibility

si21
Tera Guru

Hi experts,

We have a requirement.

Users are divided into two companies ABC and XYZ

1. Agents from ABC should see only cases belonging to these ABC company users.

2.Agents from XYZ should see only cases belonging to these XYZ company users.

3. There should be a global role that should access all the HRcase (both abc and xyz's)

 

What is the best approach for this.

TIA

 

1 REPLY 1

Bert_c1
Kilo Patron

Hi @si21 

 

A Business Rule for Query on the table works well.  I've tested the following:

 

Screenshot 2024-10-21 131921.pngScreenshot 2024-10-21 131940.png

the condition above is:

gs.getSession().isInteractive() && !(gs.hasRole("admin") || gs.hasRole("user_admin"))

and the script is:

var usr = new GlideRecord('sys_user');
var curUser = gs.getUserID();
var userCompany = '';
var userList = [];
//gs.info('curUser = ' + curUser);
usr.addQuery('sys_id', curUser);
usr.query();
if (usr.next()) {
	userCompany = usr.company.toString();
//	gs.info("Found user: " + usr.name + ", company = " + userCompany);
}
// now get a list of users with the same company
var companyUsers = new GlideRecord('sys_user');
companyUsers.addQuery('company', userCompany);
companyUsers.query();
while (companyUsers.next()) {
	userList.push(companyUsers.sys_id.toString());
}
gs.info('userList = ' + userList.toString());
current.addQuery("opened_by", "IN", userList.toString());

You could use ACL to limit, but seems a Before-Query BR is more common.