GROW

config

Avoid insert on before Business Rule

This issue is found automatically by CODA.
Time to fix: 01h

What are Business Rules?

In ServiceNow, a Business Rule is JavaScript code that runs at different stages of database operations. It can run before or after an operation like insert, update, or delete. It can also run asynchronously during saving or when loading a list view. These rules automate logic and manage data conditions.

Business Rules are a fundamental part of ServiceNow’s automation capabilities, allowing developers to control what happens when records in the database are manipulated. They can be used to enforce certain conditions, automate processes, and integrate with other systems.

Why is this an issue?

While Business Rules offer a lot of flexibility, there are certain practices that should be avoided to maintain data integrity. One such practice is the use of insert() or update() operations on other tables in a Before Business Rule.

The issue arises when a before Business Rule inserts or updates records on other tables, and then the current transaction fails in a later business rule. That happens because the before Business Rule has already changed data on another table, which can lead to a data integrity issue, where the state of the data in your system is inconsistent or incorrect.

How do I fix it?

To avoid such issues, it is recommended to make these kinds of changes in an after Business Rule instead. To do this, first confirm with your manager that the "after" option aligns with your goals, as it may not always fit your current business logic. If it is, follow these steps:

  1. In the Filter Navigator, type and enter sys_script.list.

  2. On list view, click on the business rule that needs to be changed.

  3. On the tab When to run, change the When field to after and Save.