Get the name of a Business Rule to use within the rule

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-11-2012 07:22 AM
I have business rules that use
gs.addInfoMessageto present on-screen messages for debugging purposes. I want to include the name of the business rule that's executing the gs.addInfoMessage methods within the messages themselves.
Obviously I can just insert the name of the business rule as part of the text string...
gs.addInfoMessage('Debugging text for myBusinessRule');
...but if the rule's name should be changed for some reason, I'd need to edit all of those info messages.
Similarly, I could define the rule's name as a variable...
var scrName = 'myBusinessRule'; gs.addInfoMessage('Debugging text for ' + scrName);
...but I still have to change the code if the name of the business rule changes.
Does anyone know how to programmatically return the name of the business rule that's running?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-12-2012 06:51 AM
You can define a global function that you call from your Business Rule, passing the sys_id which is unique and won't change. From the sys_id you would query the business rule table to get the name of the BR you need.
To easily get the sys_id when wrtiting your Business Rule you can select the left arrow next to "Business Rule" and select "copy sys_id".
function getBRName(sysid) {
var name = "";
var gr1 = new GlideRecord('sys_script');
gr1.addQuery('sys_id', sysid);
gr1.query();
if (gr1.next()) {
return gr1.name;
}
return "";
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-12-2012 08:27 AM
Great idea!
If no one comes back with a built-in function/method to do this, I'll probably create the function in a Script Include so that it only runs when called.