- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-29-2019 06:28 AM
Hi All,
I have written a query business to restrict record access based on few conditions. While testing, i found that business rule is being executed multiple times for a single incident record. Could you please help me understand why.
Regards,
Sreedhar
Solved! Go to Solution.
- Labels:
-
Incident Management

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-05-2019 09:33 PM
Example: I load an Incident Form.
The before Query Incident Business rule runs 3 times:
- One for the current Incident
- One for the Major Incident related list
- One for a display business rule that queries incident
Output of each query:
Display Business Rule
Related List
Each time the system runs .query() on Incident, the before query rule runs to append any queries you have added or removed from the Before query rule.
See what happens if I add "active=true" to my Incident Before Query rule:
Active=true is now appended to all queries on the Incident Table.
This is how before Query rules are used.
P.S. Conditions on fields don't work on these rules, as it isn't running on a record but on a table query.
That is the fundamental mindset shift.
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
‎09-05-2019 09:50 PM
If the intention is to only run on Incidents, you should then set it to run on Incident and not on Task with a condition. Otherwise the condition has to be evaluated for every single Task record, and there will be quite a few of those 🙂
Every single thing in the platform should be designed and built with performance in mind.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-04-2019 05:27 PM
If you really want to get to the bottom of this, check all display business rules on Task.
There will be one rule with a GlideRecord Query, which in turn is running the Query rule.
Every time you run .query() function on GlideRecord object, all Query Business Rules will are triggered to add or modify that query.
If you add this code below, you will likely see two different queries in your output:
gs.addInfoMessage( current.getEncodedQuery() );
I think you may misunderstand what a before Query rule is.
"current" in the context of a query rule does not have a sys_class_name populated.
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
‎09-04-2019 05:45 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-05-2019 09:07 PM
Thanks Paul.
Add info message for encoded query is returning same as shown in above screenshot but I don't understand why these business rules are being executed when I open business rules and or any other module in the instance.
Please help.
Regards,
Sreedhar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-05-2019 09:17 PM
This isn't actually an issue though, there is nothing wrong with a Query rule running more than once when any given page loads.
It just means there is another query on task happening when the page is loading.
It could be that a UI condition runs code that does a database query, or a display business rule. But it doesn't actually matter.
ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022