onBefore Business Rule should only update the target table

Impact area

Performance

Severity

High

Affected element

Business rules

Rule number

SN-0170

Impact

Updates on other tables from onBefore Business Rules will be committed even if the update on the target table fails. This can cause data inconsistencies. Even if successful, the source of the update on the other table may become confusing.


Remediation

Avoid updating other tables on onBefore Business rules. How can you avoid it?

  1. Using the onAfter Business Rule event can be a suitable approach for updating records on other tables. The onAfter event is triggered after the record has been saved, allowing you to safely update other tables without interfering with the current transaction.
  2. Scheduled Job: Instead of updating records on other tables directly within the onBefore Business Rule, you can create a Scheduled Job. The Scheduled Job can be triggered by the onBefore event and run at a later time or on a specific schedule. The job can handle the required updates to other tables outside the immediate context of the onBefore event.
  3. Script Include and Workflow: You can encapsulate the logic for updating other tables within a Script Include. Then, create a Workflow that triggers after the onBefore event. In the Workflow, use a Workflow Activity to call the Script Include and perform the necessary updates to other tables.
  4. Outbound Integration: If you need to update records in external systems or APIs based on the changes in the current table, you can set up an outbound integration. Create a Script Include or a Script Action in a Business Rule that triggers onBefore, which then makes the required API calls to update the records in the external system.
  5. Use Events: Instead of directly updating records in other tables, you can leverage ServiceNow Events to communicate the changes to other parts of the system. Define a custom Event and trigger it within the onBefore Business Rule. Set up event listeners or subscribers to handle the event and perform the necessary updates in the appropriate tables.

Remember, these remediation approaches depend on your specific use case and requirements. Always consider the impact, potential performance implications, and maintainability of the chosen approach. It's important to follow best practices and maintain data integrity when working with Business Rules and data updates in ServiceNow.


Time to fix

15 min




Last modified on May 23, 2023