- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2019 08:38 PM
Hi,
I am creating a before - query business rule to prevent users from accessing certain records. Similar to this link:
https://docs.servicenow.com/bundle/london-application-development/page/script/business-rules/concept/c_ExScrDefBeforeQueryBusinessRule.html
I have tested multiple times and it is working. But whenever I add a condition to the condition builder or condition script, the business rule is not working. I have tested multiple conditions that should work, even one like Active is true. But no matter what condition I add, it makes the business rule not work.
Does anyone have any ideas why adding a condition is causing this business rule to not work?
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2019 09:04 PM
Before Query Business Rules don't support the condition field.
ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2019 08:47 PM
Hi
Can you help me with some screenshots of how you have configured the BR?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2019 08:52 PM
Hi,
1-> You can use a query BRule that executes before the database query is made to prevent from accessing certain records
Write BRule on ('incident') table --- When before-query
Example Script:-
This example prevents users from accessing incident records unless they have the ITIL role are listed in the caller or Opened by field . So, for ex, when self-service users open a list of incidents, they can only see the incidents they submitted.
if(!gs.hasRole("itil")&& gs.isInteractive()){
var u = gs.getUserID();
var qc = current.addQuery("caller_id", u).addOrCondition("opened_by", u).addOrCondition("watch_list","CONTAINS", u);
gs.print("query restricted to user: "+ u);}
Or You can refer the Service Now Docs as well.
2-> So a before update business rule that goes something like with a condition of current.workflow_state.changes():
if (current.workflow_state == 'draft' || current.workflow_state == 'retired' ) {
current.u_access_group = current.assignment_group + '';
}
if (current.workflow_state == 'review') {
current.u_access_group = current.u_reviewer_group + ',' + current.assignment_group; //I made up the name of your other field and assuming the the assignment group is also able to see the knowledge article
}
else {
current.u_access_group = '';
}
Following that, I'd then create a before query business rule with the condition of !current.u_access_group.nil():
var gr = new GlideRecord('sys_user_grmember');
var grps = [];
gr.addQuery('user',gs.getUserID());
gr.query();
while(gr.next())
{
grps.push(gr.group + '');
var qc = '';
if (grps.length > 0) {
qc = current.addQuery('u_access_group', 'CONTAINS', grps[0];
}
for (var i = 1; i < grps.length; i++) {
qc.addOrCondition('u_access_group', 'CONTAINS', grps[i]);
}
**Please mark reply as Helpful/Correct, if applicable. Thanks!**

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2019 09:04 PM
Before Query Business Rules don't support the condition field.
ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022