Passing data between business rules

Drct1234
Mega Expert

Hello,

In a business rule, is it possible to know if the object that triggered the BR was another BR (and also a specific one)?
Note: these are not Display BRs.

For example:

-BusinessRuleOne: creates or updates a record..
   var gr = new GlideRecord(table_name);
   gr.property = value;
   gr.update();

-BusinessRuleTwo: runs when table_name created or updated...
  if ( ! triggeredByBusinessRuleOne() ) {
     // Do something I don't want to happen when BusinessRuleTwo was triggered BusinessRuleOne
  }
Adding fields to table_name is no possible.

Thanks!

1 ACCEPTED SOLUTION

Willem
Giga Sage
Giga Sage

Hi,

 

You can create a variable in the first business rule, if you declare it outside of the function it will be available to other business rule with higher run order.

User-defined variables are globally scoped by default. If a new variable is declared in an order 100 business rule, the business rule that runs next at order 200 also has access to the variable.

https://docs.servicenow.com/bundle/orlando-application-development/page/script/business-rules/concep...

 

var brOneTriggered = true;

 

And in the second business rule check the value of it like this:

if (!brOneTriggered) {
    // Do something I don't want to happen when BusinessRuleTwo was triggered BusinessRuleOne
 }

 

Let me know if this works for you! 🙂

View solution in original post

4 REPLIES 4

Willem
Giga Sage
Giga Sage

Hi,

You can use a scratchpad. Set the value of a Scratchpad variable on the BusinessRuleOne. Just add something like this:

g_scratchpad.brOneTriggered = true;

 

And in the second business rule check the value of it like this:

if (!g_scratchpad.brOneTriggered) {
    // Do something I don't want to happen when BusinessRuleTwo was triggered BusinessRuleOne
 }

 

Let me know if this works for you! 🙂

Thanks. I forgot to mention, these are not Display BRs.

Willem
Giga Sage
Giga Sage

Hi,

 

You can create a variable in the first business rule, if you declare it outside of the function it will be available to other business rule with higher run order.

User-defined variables are globally scoped by default. If a new variable is declared in an order 100 business rule, the business rule that runs next at order 200 also has access to the variable.

https://docs.servicenow.com/bundle/orlando-application-development/page/script/business-rules/concep...

 

var brOneTriggered = true;

 

And in the second business rule check the value of it like this:

if (!brOneTriggered) {
    // Do something I don't want to happen when BusinessRuleTwo was triggered BusinessRuleOne
 }

 

Let me know if this works for you! 🙂

Drct1234
Mega Expert

Thanks Willem!
Only comment is that first I have to check that first the variable exists to avoid throwing an exception in the second BR. JUtil isn't available in scopped apps so I can't use that.