May 28, 2023

Async Business Rules in ServiceNow

There are four types of Business Rules in ServiceNow

  1. Before business rules
  2. After business rules
  3. Display business rules
  4. Async business rules

    Business rules are usually executed synchronously, meaning they run in sequence and block further execution until completion. While effective for quick operations, this can slow down performance for longer tasks.

Async Business Rules solve this problem by executing in the background, ensuring that the main transaction completes quickly and the user interface remains responsive.


How Async Business Rules Work

  1. Trigger – Like After Business Rules, Async rules execute after a database operation (insert, update, delete, or query).
  2. Separate Thread – They run on a separate processing thread, allowing the main transaction to finish without waiting.
  3. sys_trigger Table – When triggered, ServiceNow creates a record in the sys_trigger table containing:
    • A reference to the Async Business Rule
    • The record (current) to process
  4. Scheduler Execution – Jobs are picked up by the scheduler as soon as possible for execution.

Execution Flow

  • Record change triggers the Async Business Rule.
  • ServiceNow logs the job in sys_trigger.
  • Scheduler processes the job in the background.
  • A new scripting environment is created.
  • The current record is loaded at execution time for processing.

Limitations of Async Business Rules

  • No Access to Previous Record Values – Async Business Rules cannot access the previous state of a record.
  • GlideElement Method Restrictions – The following methods do not work inside Async rule scripts:
    • changes()
    • changesTo()
    • changesFrom()
  • Condition Field Behavior – While these methods don’t work in the script directly, the condition builder and advanced condition field do support them.

Viewing Async Business Rules in ServiceNow

  1. Navigate to System Scheduler > Scheduled Jobs.
  2. Look for job names starting with ASYNC.
  3. Note: They execute quickly, so they may be hard to catch in the list.

Benefits of Async Business Rules

  • Prevents UI freezing during long-running operations.
  • Improves system performance by running processes in the background.
  • Keeps the main transaction fast and responsive.
  • Ideal for tasks that don’t require immediate user feedback.


FAQ – Async Business Rules in ServiceNow


1. When should I use Async Business Rules in ServiceNow?

Use Async Business Rules for background tasks that do not require immediate feedback to the user, such as sending notifications, updating related records, or triggering integrations. They improve performance by preventing UI delays.

2. What’s the difference between Async and After Business Rules?

After Business Rules run synchronously after a database operation and block the transaction until finished.
Async Business Rules also run after a database operation, but they execute on a separate thread in the background, allowing the main transaction to complete quickly.

3. Why doesn’t changes() work in Async Business Rules?

Async Business Rules do not have access to the previous version of a record, so GlideElement methods like changes(), changesTo(), and changesFrom() will not work inside their scripts. However, these methods still work in the condition builder and advanced condition field.

4. How do I view Async Business Rules in ServiceNow?

Go to System Scheduler > Scheduled Jobs and look for entries starting with ASYNC. These represent queued Async Business Rules, but they may disappear quickly because they execute almost instantly.

5. What are the benefits of Async Business Rules?

They prevent UI freezing, improve system responsiveness, allow long-running processes to run in the background, and reduce load on primary execution threads. 





 

 

0 comments: