Query business rule is being executed multiple times

sreedharkaliset
Mega Expert

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

1 ACCEPTED SOLUTION

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:

find_real_file.png

Display Business Rule

find_real_file.png

Related List

find_real_file.png

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:

find_real_file.png

find_real_file.png

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

View solution in original post

18 REPLIES 18

Elijah Aromola
Mega Sage

Can you post your business rule? 

sreedharkaliset
Mega Expert

Hi,

Below is sample code written:

(function executeRule(current, previous /*null when async*/) {

// Add your code here
gs.addInfoMessage("inside query task BR");
gs.addInfoMessage("sys_class_name is :"+current.getTableName());
var qc = '';
........................................

})(current, previous);

Allen Andreas
Administrator
Administrator

Can you post the actual business rule...showing the settings...like a screenshot?

Also that text isn't what is showing in your screenshot...so we have conflicting information.

Please update your screenshot if needed or show correct BR settings and script.


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Hi Allen,

 

PFB screenshots

find_real_file.png

find_real_file.png