- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-09-2014 11:46 AM
Hi,
I have a before-insert business rule defined on table sc_request; I'm not sure if it's global or not. Currently, my Javascript is entered directly into the BR but I'd like to define it as a function in a class and reference it from the BR:
- I read the documentation about doing this for global BRs but, as I mentioned above, I'm not sure if my BR is global. This seems like a good practice for any BR or can it be done only for global BRs?
- If yes, how do I define my class and functions so they'll be accessible to the BR? Is it System Includes?
- How does the BR reference the function?
A small example or pointer to documentation would be great - thank you!
Garry
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-09-2014 11:56 AM
Garry,
You will want to utilize something called (which you mentioned) Script Includes. These are scripts that can be called within various other scripting areas of ServiceNow.
Within the script include, you'll want to do something such as GetCISupportGroup:
var GetCISupportGroup = Class.create();
GetCISupportGroup.prototype = {
initialize: function(ci_sys_id) {
this.ci = ci_sys_id;
},
getSupportGroup() {
var gr = new GlideRecord('cmdb_ci');
gr.get(this.ci);
return gr.support_group;
},
type: 'GetCISupportGroup';
};
You can then create a Business Rule that populates this on Incident:
Condition: !current.assignment_group && current.cmdb_ci
Script:
current.assignment_group = GetCISupportGroup(current.cmdb_ci).getSupportGroup();
I hope this helps!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-09-2014 11:53 AM
Hi Garry,
A global business rule is any business rule where the selected Table is Global. Global business rules have no condition or table restrictions and load on every page in the system.
If you are selecting the table sc_request that means, It is not a global Business rule.
Regards,
Jesus

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-09-2014 11:56 AM
Garry,
You will want to utilize something called (which you mentioned) Script Includes. These are scripts that can be called within various other scripting areas of ServiceNow.
Within the script include, you'll want to do something such as GetCISupportGroup:
var GetCISupportGroup = Class.create();
GetCISupportGroup.prototype = {
initialize: function(ci_sys_id) {
this.ci = ci_sys_id;
},
getSupportGroup() {
var gr = new GlideRecord('cmdb_ci');
gr.get(this.ci);
return gr.support_group;
},
type: 'GetCISupportGroup';
};
You can then create a Business Rule that populates this on Incident:
Condition: !current.assignment_group && current.cmdb_ci
Script:
current.assignment_group = GetCISupportGroup(current.cmdb_ci).getSupportGroup();
I hope this helps!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-10-2014 04:16 AM
Thanks John, your example is most helpful.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-09-2014 12:48 PM
Hi Garry,
The purpose of a global business rule is to define a piece of service side scripting that you can call and reuse from other scripts. However, that functionality is in practice considered legacy with Script Includes being the better way to define reusable/callable code. The difference is that global business rules are loaded all the time and script includes are only loaded when you call them, reducing the performance impact.
Script Includes - ServiceNow Wiki