How to ignore Business rule triggered by GlideRecord

ray_bai
Kilo Contributor

We are developing a servicenow enforcer. And facing a business rule trigger problem.

For example, there are 2 before query business rules, one on incident table, one enforce on caller table.

When incident business rule(filter query) are executing, some code in this BS(business rule) will trigger caller table BS executing.

The "some code" is relate to GlideRecord query, we query caller table( or do join query on calller table).

Anybody ever encounter this problem? How to ignore the BS executing triggered by GlideRecord?

Thanks in advance!

Leo

1 ACCEPTED SOLUTION

thanks for sharing that Ray. I personally was not aware that it will also prevent query business rules.



Using a .setWorkflow(false) to prevent business rules from executing is rarely used because in most cases you want these to execute. For that reason, you have to use it with caution (specially if it doesn't execute query business rules , which also work like acls to restrict what data is retrieved during a query of a table)



Thanks,


Berny


View solution in original post

5 REPLIES 5

bernyalvarado
Mega Sage

Hi Ray,



I'm not fully sure I understand your scenario, but when you're doing an update or insert in a GlideRecord you can include a line so that such operations do not trigger business rules. That operation is .setWorkflow(false)



GlideRecord - Global - search for setWorkflow



Thanks,


Berny


bernyalvarado
Mega Sage

find_real_file.png



I hope this helps



Thanks,


Berny


Thank you Berny.


'setWorkflow' is used to enable/disable the running of any business rules that may be triggered by a particular update.



I found that it works not only for "update" but also for "query".


For example, The incident table bs code is:


var gr = new GlideRecord('ecc_action');


gr.query();



Then this query will trigger the ecc_action table bs.



Change the incident table bs code to:


var gr = new GlideRecord('ecc_action');


gr.setWorkflow(false);


gr.query();



The ecc_action table bs will not be triggered.



Is it normal? Why the servicenow official not mention the "query" action?






thanks for sharing that Ray. I personally was not aware that it will also prevent query business rules.



Using a .setWorkflow(false) to prevent business rules from executing is rarely used because in most cases you want these to execute. For that reason, you have to use it with caution (specially if it doesn't execute query business rules , which also work like acls to restrict what data is retrieved during a query of a table)



Thanks,


Berny