- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2020 07:08 PM
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!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2020 07:34 PM
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.
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! 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2020 07:23 PM
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! 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2020 07:27 PM
Thanks. I forgot to mention, these are not Display BRs.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2020 07:34 PM
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.
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! 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2020 07:55 PM
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.