Global business rules are from earlier versions of ServiceNow, before Script Includes. Developers are now supposed to use Script Includes instead of global business rules. Why is this?
Performance
GBRs are evaluated for every server interaction. Every insert,update, delete, or query of a record. They are “global”. Script Includes are different. They are loaded on-demand and cached.
How to switch to Script Includes
If you have a number of global business rules you created on a previous version of ServiceNow, you can switch them to Script Includes.
Here is an example GBR I used in for GRC report that found all Controls not linked to Authoritative Source Content . The report isn’t that important here, just how to convert that GBR to a Script Include.
New Script Includes
Your new Script Include. Just copy the GBR script you are using into the Script Include. You can convert to a more object-oriented format if you want, but that is a bonus with accompanied risk of a coding mistake. The most efficient solution is just to copy the script.
Name: getControlsNotLinkedtoASC Description: Returns Controls Not Linked to Authoritative Source Content Client Callable: true Script: getControlsNotLinkedtoASC(); function getControlsNotLinkedtoASC() { var controlList = new Array(); var grControl = new GlideRecord('grc_control'); grControl.query(); while (grControl.next()) { var grControlAuthSource = new GlideRecord('m2m_control_auth_src_content'); grControlAuthSource.addQuery('control_name', grControl.sys_id); grControlAuthSource.query(); if (!grControlAuthSource.hasNext()) { controlList.push(grControl.control_id.toString()); } } return controlList; }
Deactivate Global Business Rule
Your Existing GBR. Either delete or deactivate. I choose to delete so that my past mistakes are gone forever.
Business Rule Name: getControlsNotLinkedtoASC Table: Global [global] Active: false Script: getControlsNotLinkedtoASC(); function getControlsNotLinkedtoASC() { var controlList = new Array(); var grControl = new GlideRecord('grc_control'); grControl.query(); while (grControl.next()) { var grControlAuthSource = new GlideRecord('m2m_control_auth_src_content'); grControlAuthSource.addQuery('control_name', grControl.sys_id); grControlAuthSource.query(); if (!grControlAuthSource.hasNext()) { controlList.push(grControl.control_id.toString()); } } return controlList; }
Report
Your reports don’t need to change here. You can use them as you did previously.
Name: Controls not Linked to Authoritative Source Content Type: List Table: Control Control Number is one of javascript:getControlsNotLinkedtoASC()
Not too difficult actually. I suggest trying this one at a time, converting the least used GBR first. As you get more advanced, use object-oriented Script Includes. Also note that you can and/or should convert any custom Global Business Rule to Script Includes, any OOB global business rules should be left alone.