Bite #1: Global Business Rules are Bad News

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

Tags: , , , , ,

1 reply

Trackbacks

  1. How to Ace your ACE Report | GarrettNow

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: