Query Business rule

MA16
Tera Expert

I have some questions regarding query business rules in ServiceNow, and I'm hoping to gain some clarity on how they operate.

I currently have two query business rules configured, one is out-of-the-box (OOTB), and the other is a custom rule. Both of these rules are ordered in the same sequence. In the scenario where both business rules are triggered, I'm curious to understand how they interact.

Specifically, I'd like to know if both business rules will execute and merge the queries they individually create, or if there is a precedence that determines which query takes precedence.

Any insights or experiences with similar scenarios would be greatly appreciated. Thank you!

1 REPLY 1

-O-
Kilo Patron
Kilo Patron

You can think of it as if a script would be executed where:

var current = new GlideRecord('incident');

was written behind the screen by the system, after which in business rule 1 you wrote:

current.addQuery('active', true);

and than in the other business rule you wrote:

current.addQuery('state', 1);

 

So depending on the order you give your business rules it is as if code

var current = new GlideRecord('incident');
current.addQuery('active', true);
current.addQuery('state', 1);

or code

var current = new GlideRecord('incident');
current.addQuery('state', 1);
current.addQuery('active', true);

would be executed.

 

So (re-)ordering the business rules is important only if we consider indexes for the table at hand and you want maximum performance.

If there is an index for fields active,state but not one for state,active then it would be better to order the business rules so that the filter for field active comes 1st. And vice versa.

 

Note that this is actually added to filters that might have been included into a URL.

E.g. if one opens URL

/sys_user_list.do?sysparm_query=emailENDSWITH@gmail.com%5Emobile_phoneISNOTEMPTY

(which is filter Email ends with @gmail.com > Mobile phone is not empty) and the above mentioned query business rules exist, it will be as if code

var current = new GlideRecord('incident');
current.addEncodedQuery('emailENDSWITH@gmail.com^mobile_phoneISNOTEMPTY');
current.addQuery('state', 1);
current.addQuery('active', true);

would have been executed.