BRs Running even after setAbortAction is true in BR running before them

BhupeshG
Tera Guru

Hello Friends - I have BR X which run on Order = 50 and do the below stuff but I found even though I get error pop up saying invalid insert it does not stop another BR Y which is on   order 100,000 . Therefore the WS call is made and data is sent to External integration for an invalid ticket.

Kindly advise how can stop this

(function executeRule(current, previous /*null when async*/) {

// Add your code here

if(gs.isInteractive())

{

gs.addErrorMessage('Please assign this Incident to SNOW Group before assigning to External Group');

current.setAbortAction(true);

}

})(current, previous);

21 REPLIES 21

CMDB Whisperer
Mega Sage
Mega Sage

Although the Here is a solution that should prevent subsequent business rules from processing:

Scenario:

  • Business Rule A is triggered when Status changes to Retired, order = 100; displays message “Business Rule A was fired”, then calls current.setAbortAction(true);
  • Business Rule B is triggered when Status changes to Retired, order = 200; displays message “Business Rule B was fired”.
  • Test: Change a CI status to Retired in a List View.
  • Result: Status was reverted to Installed on the List View.  Both messages were displayed, i.e. the second Business Rule was processed even though the first Business Rule was aborted.

Fix:

  • In addition to calling current.setAbortAction(true), set current.install_status to previous.install_status.
  • Test: Change a CI status to Retired in a List View.
  • Result: Status was reverted to Installed on the List View.  Only the Business Rule A message was displayed, i.e. the second Business Rule was NOT processed.

Conclusion: if you want to prevent subsequent business rules from processing specific changes, you should not only setAbortAction(true) but also revert the specific values of the variable current that would are conditions of the subsequent business rules.  While the business rule itself will still be fired, the conditions will no longer apply if you change the attributes in current, so the actions will not be executed.


The opinions expressed here are the opinions of the author, and are not endorsed by ServiceNow or any other employer, company, or entity.

nilesh_gupta
ServiceNow Employee
ServiceNow Employee

use if (!current.isActionAborted()) in next BR