- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-06-2022 07:38 PM
I have a query business rule on Before condition. This is to restrict people from query the tickets that have been assigned to a group, only the group member would be able to see the cases, even Opened_by should not see the cases.
But my BR seems to be not working, if users opened the cases, they still are able to see the cases, which is not expected.
If I remove the filter conditions, it works as expected but it break something else that restricting people to see other cases.
Filter Conditions:
Condition:
(gs.hasRole('sn_hr_core.basic') && !gs.hasRole('admin')) && !gs.action.getGlideURI().toString().startsWith('api/now/sp')
Script:
(function executeRule(current, previous /*null when async*/) {
var currentUser = gs.getUser();
var isMember = currentUser.isMemberOf('2ea8ee6adb768300e8ec36af7c961939'); // group for "Employee Relations, Compensation and Benefits"
if(isMember == false) {
current.addQuery('assignment_group', '!=', '2ea8ee6adb768300e8ec36af7c961939'); //group for "Employee Relations, Compensation and Benefits"
}
})(current, previous);
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-06-2022 07:55 PM
Hi,
We should not apply any filter condition on Before Query business rule. Before query BR is executed when query is made to particular table and it add/append additional filter condition as per the scripted part. Query BR logic should always based on the user criteria (users groups, roles etc).
Make sure no other before query BR are running which may cause performance issue.
(function executeRule(current, previous /*null when async*/) {
var currentUser = gs.getUser();
var isMember = currentUser.isMemberOf('2ea8ee6adb768300e8ec36af7c961939'); // group for "Employee Relations, Compensation and Benefits"
if(isMember == false) {
current.addQuery('assignment_group', '!=', '2ea8ee6adb768300e8ec36af7c961939'); //group for "Employee Relations, Compensation and Benefits"
}
// add addtional filter conditions to achive your requirecment
})(current, previous);
Can you please share what is failing when you remove filter condition?
Thanks,
Anil Lande
Thanks
Anil Lande

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-06-2022 07:55 PM
Hi,
We should not apply any filter condition on Before Query business rule. Before query BR is executed when query is made to particular table and it add/append additional filter condition as per the scripted part. Query BR logic should always based on the user criteria (users groups, roles etc).
Make sure no other before query BR are running which may cause performance issue.
(function executeRule(current, previous /*null when async*/) {
var currentUser = gs.getUser();
var isMember = currentUser.isMemberOf('2ea8ee6adb768300e8ec36af7c961939'); // group for "Employee Relations, Compensation and Benefits"
if(isMember == false) {
current.addQuery('assignment_group', '!=', '2ea8ee6adb768300e8ec36af7c961939'); //group for "Employee Relations, Compensation and Benefits"
}
// add addtional filter conditions to achive your requirecment
})(current, previous);
Can you please share what is failing when you remove filter condition?
Thanks,
Anil Lande
Thanks
Anil Lande
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-06-2022 08:01 PM
Hi Anil,
Thanks for reply.
I removed the filter condition, it works find for filtering out the cases that in the assignment group. But it broke something else, like people are no longer see the cases that they were able to see.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-06-2022 08:39 PM
Hi,
Can you please check if there is any other before query BR running on same table?
I don't see any issue with this BR as it is only restrict access to cases assigned to particular group if user is not member of that group. As per this BR users should see all other cases if ACL/any other BR is not restricting access.
Thanks,
Anil Lande
Thanks
Anil Lande