How to Restrict Access to test Table Using Before Query Business Rule or ACL Based on User Departme
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
7 hours ago
Hi everyone,
I am working on restricting access to the test table so that only users belonging to the it or csa Department can view the data.
Requirements:
Users from it or csa Department should be able to see and interact with the records normally.
Users from other Departments should not be able to see any records.
I want to implement this using ACL or Before qurry business rule:
Can someone please help me in code, If possible provide with screenshot and link.
Thank you,
Vivek
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
6 hours ago - last edited 6 hours ago
Hi @vivek11
If you really want to hide records entirely from users in other departments, you can filter the query before it runs.
1. Go to Business Rules > New.
2. Set:
- Table: your table (u_test)
- When: before
- Insert/Update/Delete: unchecked
- Query: checked
3. Script:
(function executeRule(current, previous /*null when async*/) {
var userDept = gs.getUser().getDepartmentID();
if (!userDept) {
current.addQuery('sys_id', ''); // no records
return;
}
var dept = new GlideRecord('cmn_department');
if (dept.get(userDept)) {
if (dept.name != 'it' && dept.name != 'csa') {
// Exclude all records for users outside IT or CSA
current.addQuery('sys_id', '');
}
}
})(current, previous);