logo

NJP

How to "bypass" the setAbortAction restriction for scoped applications in a business rule

Import · Nov 09, 2021 · article
  • Working in a scoped application
  • Using the "OOTB" approval flow to create approvals
  • The Approval table sysapproval_approver is in Global
  • Creating a scoped business rule on the approval record with a script that uses setAbortAction() will fail with something like this: "Access to api 'setAbortAction' from scope 'xxxxx' has been refused due to the api's cross-scope access policy"
  • Creation restrictions across application scopes : Business Rules: You cannot write scripts and you cannot abort the database transaction.

image

Of course you can try to create cross scope privileges to achieve this or move the BR to GLOBAL, but the following possible workaround is much easier than that while keeping the BR inside the scoped application:

Possible Solution (while keeping everything in scope without creating cross scope privileges):

  1. Move all the logic of the business rules script that would define when to abort the database transaction to a scoped script include (client callable) that would just return true or false if a specific condition is given
  2. Create a scoped Business Rule and use the OOTB check box "Abort Action (abort_action)" This will work even cross scope
  3. In the "Advanced" section of the business rule add a condition that just calls the script include.
The Script Include:

image

The Business Rule:

image

image

View original source

https://www.servicenow.com/community/developer-articles/how-to-quot-bypass-quot-the-setabortaction-restriction-for/ta-p/2323711