The CreatorCon Call for Content is officially open! Get started here.

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

jim pisello
Giga Expert

I have business rules that use

gs.addInfoMessage
to 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?
2 REPLIES 2

alessandro_deso
ServiceNow Employee
ServiceNow Employee

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 "";
}


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.