1. Synchronous Business Rule
- Execution Timing: Runs immediately within the current user session, typically before or after a database operation (insert, update, delete, query).
- Impact on User Experience: The user has to wait for the rule to complete before they can continue interacting with the platform. For example, if a synchronous Business Rule takes a long time to execute, the form submission or the record save process might be delayed.
- Use Case: Suitable for scenarios where the outcome of the Business Rule needs to be immediate, such as:
- Validating data before insert/update.
- Setting field values that should appear immediately when a record is displayed or saved.
- Example:
-
if (current.priority == 1) { current.impact = 1; }
- This rule will execute immediately during the save operation, and the field will be updated before the form is presented back to the user.
2. Asynchronous Business Rule
- Execution Timing: Runs in the background after the current transaction has been completed. It does not block the user or affect the immediate form submission.
- Impact on User Experience: The user does not have to wait for the rule to finish executing, as the rule runs after the response is sent to the client. This makes it ideal for processes that may take time, but don't need to be completed before the form submission finishes.
- Use Case: Suitable for tasks that don't need to impact the user's immediate interaction, such as:
- Sending email notifications.
- Updating related records or logs.
- Performing integrations or calculations that are not time-sensitive.
- Example:
<code>
// Send email notification after an incident is created gs.eventQueue('incident.created', current, gs.getUserID(), gs.getUserName());
This rule will run after the record is inserted into the database, without delaying the user's experience.
Key Differences:
Feature
Synchronous Business Rule
Asynchronous Business Rule
Execution Time
Runs immediately within the current user session.
Runs in the background after the transaction is completed.
User Impact
User waits for the rule to execute before the form or action completes.
User continues working without waiting for the rule to complete.
Use Case
Immediate field updates, validation checks, or error handling.
Background tasks like notifications, logging, or batch updates.
Performance
Can impact performance if there are heavy processes, as it runs in real-time.
Better for performance, as it runs in the background without affecting user interaction.
Timing of Results
Results are visible immediately.
Results are visible after the business rule completes in the background.
Business Rule Type
Typically used for before
and after
Business Rules.
Typically used for async
Business Rules.
When to Use:
- Synchronous: Use when the results of the Business Rule are critical to the transaction, and the user needs immediate feedback, such as validating field values before allowing the record to save.
- Asynchronous: Use when the task can run in the background without affecting the immediate user experience, such as sending emails or logging data after a record is created or updated.
Choosing between sync and async depends on the nature of the task and how quickly the user needs the results.