What is a Global Business Rule?
These are business rules that are created with “Global” in the Table field. In the past these were used to define functions and other useful code that the developer wanted to use throughout the system in other business rules.
Why are they bad?
Global Business Rules are included in every single server-side transaction without regard to whether they’re actually needed. This causes a lot of extra overhead and can lead to performance issues — which become even more noticeable as the number of users on the system increases.
What’s the solution?
Today it’s recommended to put any reusable code in a Script Include. By creating JavaScript Objects or putting single functions within Script Includes, they are automatically included whenever they are called.
Example:
Script Include Name: getAdmins
Script:
function getAdmins() { var usr = new GlideRecord("sys_user_has_role"); var admins = []; usr.addQuery("role.name", "admin"); usr.query(); while(usr.next()) { admins.push(usr.sys_id); } return admins.join(); }
Usage:
Anytime “getAdmins()” is used in a Business Rule, another script include, a scheduled job, etc., the proper Script Include will automatically be included.
The Bottom Line
Avoid Global Business Rules at all costs!
Note: In order to supply helpful content more often, I’m going to add frequent “Bites” that are very short tidbits, with the lengthier posts reserved for when I have something substantial to share.
Categories: Developers, Scripting Tips
Leave a Reply