Skip to content · Zum Inhalt

Understanding Trigger Events: How Business Rules Know When to Execute

Introduction

One of the most critical but often misunderstood aspects of business rules management is understanding when rules execute. Unlike scheduled jobs that run at specific times or background processes that run continuously, business rules in QUALIA Rule Engine are event-driven—they execute automatically in response to specific user actions or system events.

Choosing the correct trigger event for your business rules is fundamental to achieving your business objectives. Use the wrong trigger, and your rule might execute too early (before required data is available), too late (after the transaction is committed), or not at all. Understanding trigger events transforms business rules from mysterious black boxes into predictable, powerful automation tools.

This comprehensive guide explains how trigger events work in Business Central and QUALIA Rule Engine, when to use each event type, common patterns for different business scenarios, and troubleshooting techniques when rules don't fire as expected.

What Are Trigger Events?

Definition

A trigger event is a specific point in a Business Central transaction's lifecycle when QUALIA Rule Engine checks whether business rules should execute. Think of trigger events as "hooks" where your business logic can intercept and evaluate transactions as they happen.

How Trigger Events Work

When you configure a rule set in QUALIA Rule Engine, you specify:

Trigger Table: Which Business Central table the rule monitors (e.g., Sales Header, Item, Customer)

Trigger Event: Which event on that table activates the rule (e.g., Before Insert, After Modify)

When a user or process performs an action that matches both the table and event:

Business Central raises the event

QUALIA Rule Engine intercepts the event

Rule Engine checks if scenarios match

If scenarios pass, Rule Engine evaluates conditions

If conditions are true, Rule Engine executes actions

Event-Driven vs. Polling

Event-driven (QUALIA Rule Engine):

Rules execute instantly when events occur

Zero latency between transaction and validation

No system overhead when no transactions occur

Precise control over when validation happens

Polling (alternative approach):

System checks periodically for changes

Delayed detection of issues

Constant system overhead regardless of activity

Less precise timing

QUALIA Rule Engine's event-driven architecture ensures immediate validation with minimal system impact.

Available Trigger Events in Business Central

Business Central provides various trigger events at different points in a record's lifecycle. QUALIA Rule Engine supports the most commonly used events for business rules.

Before Insert

When it fires: Immediately before a new record is created in the database, but after field values are set

State of data:

New record fields are populated with user-entered or default values

Record does NOT yet exist in database

Primary key may be assigned

Related tables are accessible

Previous values are not available (no record existed)

Typical use cases:

Validate new record data before allowing creation

Block creation based on business rules

Set default values or auto-populate fields

Verify prerequisites exist

Check for duplicates

Example scenarios:

Prevent creating sales orders for blocked customers

Validate that credit limits aren't exceeded

Ensure required custom fields are filled

Block orders for customers with overdue invoices

Verify item availability before order creation

Outcome possibilities:

Allow: Record is inserted into database

Block (Error): Record creation is prevented, user sees error message

Warn: User sees warning but can proceed

After Insert

When it fires: Immediately after a new record is successfully created in the database

State of data:

New record exists in database with all field values

System-generated fields are populated (entry numbers, timestamps, etc.)

Record is committed unless within a larger transaction

Related tables accessible

Typical use cases:

Trigger notifications about new records

Create related records automatically

Update summary tables or caches

Send alerts to other systems

Log creation events

Example scenarios:

Send email notification when high-value order is created

Create approval workflow entry for new vendor

Update dashboard counters

Trigger integration with external system

Log new customer creation for audit

Important: After Insert cannot prevent the record creation (it already happened). Use Before Insert for blocking scenarios.

Outcome possibilities:

Notification: Send alerts, emails, messages

Assignment: Populate fields in related tables

Integration: Trigger external systems

Cannot block: Record is already created

Before Modify

When it fires: Immediately before changes to an existing record are saved to the database

State of data:

Modified field values reflect user changes

Original (pre-modification) values are available through field references

Record still has original values in database until modification commits

Related tables accessible

Typical use cases:

Validate changes before allowing them

Block unauthorized modifications

Verify business rule compliance on edits

Prevent invalid state transitions

Enforce data integrity

Example scenarios:

Prevent reducing credit limit below current balance

Block price changes exceeding authorization threshold

Prevent changing order status without approval

Verify quantity changes don't create negative inventory

Ensure required fields aren't blanked out

Comparing old vs. new values: Before Modify is unique because you can compare original and new values:

[18:59] refers to the NEW (modified) value of field 59 in table 18

Previous values can be accessed if Business Central code stores them

Outcome possibilities:

Allow: Changes are saved to database

Block (Error): Changes are rejected, record retains original values

Warn: User sees warning but can save changes

After Modify

When it fires: Immediately after changes to a record are successfully saved to the database

State of data:

Record in database now has updated values

Previous values are generally not available

Changes are committed unless within larger transaction

Related tables accessible

Typical use cases:

Notify stakeholders of changes

Trigger recalculations based on changes

Update related records

Log change events

Sync changes to external systems

Example scenarios:

Email sales manager when order amount increases significantly

Update customer totals when order is modified

Trigger inventory reallocation when order quantity changes

Send notification when customer is blocked

Log price changes for audit

Important: After Modify cannot prevent the change (it already happened). Use Before Modify for blocking scenarios.

Outcome possibilities:

Notification: Alerts about changes

Updates: Modify related records

Integration: Sync to external systems

Cannot block: Changes already saved

Before Delete

When it fires: Immediately before a record is deleted from the database

State of data:

Record still exists in database with all values

Related tables accessible

Can still access all field values

Deletion has not yet occurred

Typical use cases:

Prevent deletion of records that are referenced elsewhere

Verify user has authority to delete

Block deletion based on record state

Enforce retention policies

Verify dependencies are handled

Example scenarios:

Prevent deleting customer with open orders

Block item deletion if inventory transactions exist

Prevent deletion of posted documents

Verify cascading deletion rules

Ensure user has deletion authority

Outcome possibilities:

Allow: Record is deleted from database

Block (Error): Deletion is prevented, record remains

Warn: User sees warning but can proceed with deletion

After Delete

When it fires: Immediately after a record is successfully deleted from the database

State of data:

Record NO LONGER exists in database

Field values from deleted record may be available in event parameters

Related tables accessible

Deletion is committed unless within larger transaction

Typical use cases:

Cleanup related records

Send deletion notifications

Log deletion events for audit

Update summary counts

Trigger external system updates

Example scenarios:

Log deletion of customer for audit trail

Notify supervisor when order is deleted

Update dashboard counts

Archive deleted record to history table

Trigger external system cleanup

Important: After Delete cannot prevent deletion (already happened). Use Before Delete for blocking scenarios.

Outcome possibilities:

Logging: Record deletion events

Cleanup: Remove related data

Notification: Alert about deletion

Cannot block: Record already deleted

On Validate (Field-Level Triggers)

When it fires: When a specific field's value changes and validation runs

State of data:

Field has new value

Record may or may not be saved yet

Other fields accessible

Previous field value may be available

Typical use cases:

Field-level validation

Auto-populate related fields

Perform lookups based on field value

Validate field value format or range

Example scenarios:

Validate email format when email field changes

Auto-populate customer name when customer number entered

Verify discount percentage is within allowed range

Check that date is not in the past

Note: QUALIA Rule Engine primarily uses table-level triggers (Insert, Modify, Delete), but field validation can be implemented using Before Modify with specific field checks.

Choosing the Right Trigger Event

Selecting the appropriate trigger event is critical for rule effectiveness. Here's a decision framework:

Decision Tree

Use Before Events When...

You need to validate BEFORE allowing action:

Prevent order creation if credit limit exceeded

Block price changes exceeding authorization

Stop deletion of referenced records

You need data to be in valid state BEFORE commit:

Ensure required fields are filled before insert

Verify state transitions are legal before modify

Confirm dependencies are resolved before delete

You need to give users immediate feedback:

"This order exceeds credit limit" (before creation)

"You cannot reduce the credit limit below current balance" (before modify)

"This customer has open orders and cannot be deleted" (before delete)

You might need to STOP the transaction:

Any validation that can fail should use Before events

Prevents bad data from entering the database

Provides clear, immediate user feedback

Use After Events When...

You need to react to completed actions:

Send notification that order was created

Update dashboard when customer is modified

Log deletion event for audit

You need system-generated values:

Entry numbers assigned during insert

System timestamps

Auto-generated fields

You're triggering external systems or workflows:

After Insert: Trigger approval workflow for new vendor

After Modify: Sync customer changes to CRM

After Delete: Notify external system of deletion

You're performing non-blocking actions:

Notifications, emails, alerts

Logging and auditing

Background updates

External integrations

You cannot afford to block the user:

If your action might fail, don't use After events to block (too late)

After events for fire-and-forget scenarios

Common Trigger Event Patterns

Pattern 1: Validation on Entry (Before Insert)

Business need: Ensure new records meet business rules before creation

Configuration:

Trigger Table: Target table (e.g., Sales Header - Table 36)

Trigger Event: Before Insert

Scenarios: Filter to relevant records (e.g., Document Type = Order)

Conditions: Business rule validation

Actions: Error message if validation fails

Example: Credit Limit Check on New Order

Rule Set: SALES-CREDIT-CHECK
Trigger Table: 36 (Sales Header)
Trigger Event: Before Insert

Scenario 1: [36:1] is 'Order'
Scenario 2: [18:39] is false  // Customer not blocked

Linked Table: Customer (18)
Link: Customer No. = Sell-to Customer No.

Condition: {[36:109] + [18:61]} is >[18:59]
Action: Error - "Credit limit exceeded. Order amount $[36:109] plus current balance $[18:61] exceeds credit limit $[18:59]

Outcome: User cannot create order if it would exceed credit limit

Pattern 2: State Transition Validation (Before Modify)

Business need: Ensure changes to existing records follow business rules

Configuration:

Trigger Table: Target table

Trigger Event: Before Modify

Scenarios: Filter to relevant modifications

Conditions: Validate the change

Actions: Error if change is invalid

Example: Prevent Credit Limit Reduction Below Balance

Rule Set: CUST-CREDITLIMIT-PROTECT
Trigger Table: 18 (Customer)
Trigger Event: Before Modify

Condition: [18:59] is <[18:61]
// New credit limit < current balance

Action: Error - "Cannot reduce credit limit to $[18:59] because current balance is $[18:61]

Outcome: User cannot reduce credit limit if customer balance exceeds new limit

Pattern 3: Deletion Protection (Before Delete)

Business need: Prevent deletion of records that are referenced or important

Configuration:

Trigger Table: Target table

Trigger Event: Before Delete

Conditions: Check if record can be safely deleted

Actions: Error if deletion should be blocked

Example: Prevent Customer Deletion with Orders

Rule Set: CUST-DELETE-CHECK
Trigger Table: 18 (Customer)
Trigger Event: Before Delete

Linked Table: Sales Header (36)
Link: Sell-to Customer No. = Customer No.

Condition: COUNT([36:1]) > 0
// If any sales documents exist

Action: Error - "Cannot delete customer [18:2]. This customer has [COUNT(36:1)]

Outcome: User cannot delete customer if sales documents exist

Pattern 4: Notification on Creation (After Insert)

Business need: Alert stakeholders when important records are created

Configuration:

Trigger Table: Target table

Trigger Event: After Insert

Scenarios: Filter to records requiring notification

Conditions: Determine notification criteria

Actions: Send email, notification, or alert

Example: Alert Sales Manager of Large Orders

Rule Set: SALES-LARGE-ORDER-ALERT
Trigger Table: 36 (Sales Header)
Trigger Event: After Insert

Scenario: [36:1] is 'Order'

Condition: [36:109] is >100000
// Order amount exceeds $100,000

Action: Email
To: [email protected]
Subject: "Large Order Created: $[36:109]"
Body: "New sales order [36:3] for customer [18:2] with amount $[36:109] was created by [USERID]

Outcome: Sales manager receives email whenever large order is created

Pattern 5: Automatic Field Population (Before Insert)

Business need: Auto-populate fields based on other field values or business logic

Configuration:

Trigger Table: Target table

Trigger Event: Before Insert (to populate before record is saved)

Conditions: When to populate

Actions: Assign action to set field value

Example: Auto-Assign Salesperson Based on Territory

Rule Set: AUTO-ASSIGN-SALESPERSON
Trigger Table: 18 (Customer)
Trigger Event: Before Insert

Linked Table: Territory (226)
Link: Territory Code = Territory Code

Condition: [18:29]

Outcome: When new customer is created with WEST territory, salesperson is automatically assigned

Pattern 6: Audit Logging (After Delete)

Business need: Maintain audit trail of deleted records

Configuration:

Trigger Table: Target table

Trigger Event: After Delete

Actions: Log to custom audit table or send notification

Example: Log Customer Deletions

Rule Set: AUDIT-CUSTOMER-DELETE
Trigger Table: 18 (Customer)
Trigger Event: After Delete

Action: Insert (to custom audit log table)
// This would require custom action or integration
// Log: Customer No., Name, Deleted By, Deleted Date/Time

Alternative: Email notification
To: [email protected]
Subject: "Customer Deleted"
Body: "Customer [18:1] - [18:2] was deleted by [USERID] on [DATETIME]

Outcome: Audit trail maintained for all customer deletions

Pattern 7: Multi-Step Validation (Before Insert with Multiple Rules)

Business need: Complex validation requiring multiple checks

Configuration:

Multiple rules within single rule set

All using Before Insert on same table

Each rule checks different aspect

Each can independently block transaction

Example: Comprehensive Order Validation

Rule Set: SALES-ORDER-VALIDATION
Trigger Table: 36 (Sales Header)
Trigger Event: Before Insert

Rule 1: Credit Limit Check
  Condition: {[36:109] + [18:61]} is >[18:59]
  Action: Error - "Credit limit exceeded."

Rule 2: Customer Status Check
  Condition: [18:39] is true
  Action: Error - "Customer is blocked for [18:40]."

Rule 3: Minimum Order Check
  Condition: [36:109] is <500
  Action: Warning - "Order amount $[36:109] is below minimum $500. Confirm to proceed."

Rule 4: Required Fields Check
  Condition: [36:43]

Outcome: Order creation requires passing all validation rules

Advanced Trigger Event Concepts

Event Execution Order

When multiple rule sets exist on the same table with the same event, they execute in sequence (not specific order guaranteed). Each rule set evaluates independently.

Best practice: Don't rely on specific execution order. Make each rule set independent.

Transaction Context

Understanding transactions:

Before events occur within transaction context

If Before event raises error, entire transaction rolls back

After events also within transaction unless explicitly committed

Multiple table events may be within single transaction

Example: Creating sales order with lines:

Before Insert fires for Sales Header

Sales Header inserted

For each line: Before Insert fires for Sales Line

All lines inserted

After Insert fires for Sales Header

After Insert fires for each Sales Line

Transaction commits

Implication: Before Insert error on ANY sales line blocks ENTIRE order creation

Recursive Triggers

What is recursive trigger: A rule that modifies the same table it's monitoring, potentially triggering itself again

Example of recursion risk:

Prevention:

QUALIA Rule Engine likely has recursion prevention

Design rules to avoid modifying trigger table

Use different events (After instead of Before if modifying same table)

Use scenarios to prevent re-execution

Compound Events (Multiple Tables)

Business scenario: Order creation involves multiple tables

Tables involved:

Sales Header (36) - Order header

Sales Line (37) - Order lines

Item (27) - Product information

Customer (18) - Customer information

Rule strategy:

Validate header: Before Insert on Sales Header (36)

Validate each line: Before Insert on Sales Line (37)

React to complete order: After Insert on Sales Header (36)

Coordination: Each table's rules operate independently. Design scenarios carefully to handle proper context.

Troubleshooting Trigger Events

Problem: Rule Not Firing

Possible causes:

1. Wrong trigger event:

Using After Insert but trying to block creation (use Before Insert)

Using Before Modify but record is being inserted (use Before Insert)

2. Scenarios filtering out transaction:

Scenario conditions not matching

Check Validation Log to see if scenario evaluated false

3. Wrong trigger table:

Monitoring Sales Header but transaction is on Sales Line

Verify which table is actually being modified

4. Rule or rule set disabled:

Check Enable checkbox on rule set, rules, conditions

5. User not in rule group:

Rule assigned to specific group, user not member

Troubleshooting steps:

Check Validation Log - does rule appear at all?

If not in log: Rule set disabled or wrong table/event

If in log but scenario failed: Refine scenarios

If scenario passed but condition not evaluated: Check condition enable status

If condition evaluated but didn't fire: Check formula logic

Problem: Rule Firing at Wrong Time

Symptoms:

Error message appears after transaction is already saved

Notification doesn't include system-generated values

Rule fires for wrong record types

Diagnosis:

Firing too late:

Using After event when should use Before

Change to Before Insert/Modify/Delete if blocking is needed

Firing too early:

Using Before event but need system-generated values

Change to After event if blocking is not required

Firing for wrong records:

Scenarios too broad or missing

Add scenarios to filter appropriately

Problem: Rule Firing Multiple Times

Symptoms:

Same validation runs multiple times for one transaction

Multiple emails sent for single event

Causes:

1. Multiple rule sets on same trigger:

Several rule sets monitoring same table/event

Verify each rule set has unique purpose

Consolidate if redundant

2. Recursive modification:

Rule modifies same table it monitors

Triggering itself repeatedly

Add scenario to prevent re-execution or use different approach

3. Transaction retry logic:

Business Central may retry failed transactions

Each retry triggers rules

Ensure idempotency if possible

4. Multiple related records:

Creating order with 10 lines triggers After Insert 10 times

This is expected behavior

Filter scenarios if needed

Problem: Field Values Not as Expected

Symptoms:

Placeholder shows blank when field has value

Field comparison doesn't work as expected

Linked table data is empty

Causes:

1. Before Insert - record doesn't exist yet:

Some fields may not be populated yet

Primary key may not be assigned

Use After Insert if you need complete record

2. Linked table filter incorrect:

Filter field doesn't match

Check filter configuration in Source References

Verify field numbers are correct

3. Field value cleared during event:

Business Central code may modify fields during event

Verify field state at event timing

4. Wrong field reference:

Using wrong table number or field number

Double-check field numbers in table metadata

Troubleshooting:

Check Validation Log for placeholder values

Verify actual field values in database

Test with known data

Review linked table configuration

Best Practices for Trigger Events

1. Match Event to Purpose

Blocking action: Before event

Notifying stakeholders: After event

Populating fields: Before event

Logging: After event

2. Use Scenarios to Optimize Performance

Don't evaluate conditions on every transaction:

3. Provide Clear, Immediate Feedback

For Before events with errors:

Explain what's wrong

Show relevant data values

Provide specific resolution steps

Include contact information if applicable

4. Handle Edge Cases

Consider:

What if linked table has no matching record?

What if field is blank or null?

What if amount is zero or negative?

What if user has partial permissions?

5. Test at Correct Event Timing

Test scenarios:

Create test record to test Before/After Insert

Modify test record to test Before/After Modify

Delete test record to test Before/After Delete

Check Validation Log to verify firing

6. Document Event Choice

In rule description, note:

Why this event was chosen

What it prevents or enables

Any timing considerations

7. Coordinate Multi-Table Rules

When business process spans tables:

Map out transaction flow

Identify which table to monitor for each validation

Ensure rules don't conflict

Conclusion

Understanding trigger events is fundamental to effective business rules management. The right trigger event ensures your rules execute at precisely the right moment—early enough to prevent problems but late enough to have necessary data.

Key principles:

Before events for prevention:

Validate before allowing action

Block transactions that violate policies

Provide immediate user feedback

Ensure data integrity

After events for reaction:

Notify stakeholders

Trigger workflows

Update related systems

Log events

Event selection framework:

Determine if you need to block or notify

Identify the transaction type (Insert, Modify, Delete)

Choose Before for blocking, After for notification

Use scenarios to optimize performance

Test thoroughly at the correct event timing

By mastering trigger events, you transform QUALIA Rule Engine from a simple validation tool into a sophisticated, precisely-timed business automation platform that executes exactly when needed and delivers maximum value with minimal friction.

Related Reading:

Scenarios vs. Conditions: Mastering the Two-Tier Validation Model

Understanding the Business Rules Lifecycle: From Design to Deployment

Performance Tuning Your Business Rules: Optimization Strategies

Common Business Rules Patterns: 20 Real-World Examples