Scenarios vs. Conditions: Mastering the Two-Tier Validation Model
Introduction
One of the most distinctive and powerful architectural features of QUALIA Rule Engine is its two-tier validation model: Scenarios and Conditions. While this dual-layer approach might initially seem like unnecessary complexity, it's actually a sophisticated design that delivers significant performance benefits and logical clarity.
Many users starting with QUALIA Rule Engine ask: "Why do I need both scenarios and conditions? Can't I just put all my logic in conditions?" Understanding the critical differences between these two layers—and when to use each—transforms good rule implementations into exceptional ones that perform efficiently at scale.
This comprehensive guide demystifies scenarios and conditions, explains the strategic thinking behind the two-tier model, provides practical patterns for using each layer effectively, and shares optimization techniques that can dramatically improve rule performance.
The Two-Tier Validation Model: Overview
What Are Scenarios?
Scenarios are the first tier of validation—a high-level filter that quickly determines whether a transaction is relevant to a rule set.
Think of scenarios as a pre-flight check that asks: "Should we even bother evaluating detailed business rules for this transaction?"
Characteristics:
Evaluated first, before conditions
Typically simple, fast comparisons
Focus on broad categorization
Filter out irrelevant transactions
Performance optimization layer
Multiple scenarios combined with AND logic
Example scenarios:
Document Type is 'Order' (not Quote, Invoice, etc.)
Customer is not blocked
Transaction date is within current fiscal year
Amount is greater than zero
Department is 'Sales' or 'Marketing'
What Are Conditions?
Conditions are the second tier of validation—detailed business logic that determines whether a business rule should fire.
Think of conditions as the actual business rules that implement your policies and validations.
Characteristics:
Evaluated second, only if scenarios pass
Can be complex formulas with calculations
Implement specific business policies
Determine rule execution
Can reference linked tables and perform calculations
Each condition is independent
Example conditions:
Order Amount + Customer Balance > Credit Limit
Discount Percentage > Maximum Allowed Discount
Inventory Quantity < Reorder Point
Payment Terms don't match Customer Category
Price is less than Cost + Minimum Margin
Why Two Tiers Instead of One?
The two-tier model provides several critical advantages:
1. Performance optimization:
Example: Credit limit rule without scenarios:
Evaluates credit limit logic for EVERY transaction
Runs on Quotes, Invoices, Returns, Blanket Orders, etc.
Accesses customer table for all document types
Performs calculations unnecessarily
Credit limit rule with scenarios:
Scenario 1: Document Type = 'Order' (filters out 80% of transactions)
Scenario 2: Customer not blocked (filters out another 5%)
Only remaining 15% evaluates credit limit calculation
85% performance improvement
2. Logical clarity:
3. Reusability:
4. Debugging simplification:
Scenarios: The First Tier (Pre-Flight Check)
Purpose of Scenarios
Scenarios answer the question: "Is this transaction relevant to this rule set?"
What scenarios should check:
Document type or category
Record status or state
User or role
Department or division
Date ranges
Simple field value checks
Basic applicability filters
What scenarios should NOT check:
Complex business logic
Calculations involving multiple fields
Linked table data comparisons
Detailed policy enforcement
Scenario Evaluation Logic
Multiple scenarios combined with AND:
Placeholders Used in These Scenarios:
[36:1]- Sales Header (Table 36): Document Type (Field 1) - Filters to order documents[18:39]- Customer (Table 18): Blocked (Field 39) - Customer blocked status (false = not blocked)[36:69]- Sales Header (Table 36): External Document No. (Field 69) - Checks if external doc no. is blank
All scenarios must pass for conditions to be evaluated.
Scenario failure = rule set skipped (logged in Validation Log but no conditions evaluated).
Scenario Syntax
Scenarios use the same Business Central filter expression syntax as conditions:
Comparison operators:
Range operators:
Multiple values (OR within field):
Wildcards for text:
Empty/non-empty:
Effective Scenario Design Patterns
Pattern 1: Document Type Filtering
Most common scenario: Filter by document or record type
Variations:
Placeholders Used:
[36:1]- Sales Header (Table 36): Document Type (Field 1) - Filters by document type (Order, Quote, Invoice, etc.)
Pattern 2: Status/State Filtering
Filter by record status to skip irrelevant states
Placeholders Used:
[36:120]- Sales Header (Table 36): Status (Field 120) - Document status (0=Open, 1=Released, etc.)[18:39]- Customer (Table 18): Blocked (Field 39) - Customer blocked status[27:54]- Item (Table 27): Blocked (Field 54) - Item blocked status
Pattern 3: Date Range Filtering
Apply rules only within specific time periods
Placeholders Used:
[36:99]- Sales Header (Table 36): Order Date (Field 99) - Order/posting date for date range filtering
Pattern 4: Amount/Value Threshold Filtering
Skip small transactions to focus on material amounts
Placeholders Used:
[36:109]- Sales Header (Table 36): Amount Including VAT (Field 109) - Total order amount for threshold filtering
Pattern 5: User/Department Filtering
Apply rules to specific organizations or roles
Placeholders Used:
[36:77]- Sales Header (Table 36): Shortcut Dimension 1 Code (Field 77) - Department/division filtering[1:101]- User (Table 1): User ID (Field 101) - Identifies the current user
Pattern 6: Required Field Check (Existence Filtering)
Ensure required data exists before evaluating business logic
Placeholders Used:
[36:2]- Sales Header (Table 36): Sell-to Customer No. (Field 2) - Customer number existence check[36:12]- Sales Header (Table 36): Sell-to Contact No. (Field 12) - Contact/salesperson assignment check
Why as scenario instead of condition? If the field is blank, subsequent conditions might reference it and cause errors. Filtering at scenario level prevents condition evaluation entirely.
Scenario Optimization Strategies
Strategy 1: Order Scenarios by Elimination Rate
Place most selective scenarios first:
Placeholders Used:
[36:39]- Sales Header (Table 36): External Document No. (Field 39) - Low selectivity field[36:1]- Sales Header (Table 36): Document Type (Field 1) - High selectivity field for optimal filtering
How to determine order:
Identify which scenario filters out the most transactions
Place that scenario first
Order remaining scenarios by decreasing selectivity
Measurement approach:
Review Validation Log over representative time period
Count how many transactions have each field value
Calculate percentages
Reorder scenarios accordingly
Strategy 2: Use Range Instead of Multiple Comparisons
Single range is faster than combining multiple scenarios:
Placeholders Used:
[36:109]- Sales Header (Table 36): Amount Including VAT (Field 109) - Amount threshold for range filtering
Strategy 3: Combine Multiple Values with OR
Use pipe (|) instead of multiple scenarios:
Strategy 4: Avoid Calculations in Scenarios
Keep scenarios simple:
Placeholders Used:
[36:109]- Sales Header (Table 36): Amount Including VAT (Field 109) - Order amount[18:59]- Customer (Table 18): Credit Limit (Field 59) - Credit limit for comparison{([36:109] * 1.10)}- Calculated expression: Order amount with 10% buffer
Why: Scenarios should be fast, simple filters. Complex calculations belong in conditions.
Strategy 5: Minimize Linked Table Access in Scenarios
Scenarios should ideally use only trigger table fields:
Note: If linked table is needed in scenarios, ensure it's also needed in conditions. Don't link tables only for scenario filtering.
Conditions: The Second Tier (Business Logic)
Purpose of Conditions
Conditions answer the question: "Does this transaction violate a business rule?"
What conditions should check:
Business policy enforcement
Multi-field calculations
Comparisons across linked tables
Complex logical expressions
Data validation rules
Approval thresholds
What conditions should NOT check:
Basic applicability (use scenarios)
Simple document type filtering (use scenarios)
Performance-optimizing filters (use scenarios)
Condition Evaluation Logic
Each condition is independent:
Conditions are independent (unlike scenarios which are AND-combined).
Multiple conditions can fire for the same transaction.
Condition Syntax
Conditions use Business Central filter expressions plus calculation operators:
Arithmetic operators:
Comparison in formulas:
Complex expressions:
Field comparisons:
Effective Condition Design Patterns
Pattern 1: Credit Limit Validation
Business rule: Order cannot exceed customer credit limit
Pattern 2: Discount Authorization
Business rule: Discounts exceeding threshold require approval
Pattern 3: Inventory Availability
Business rule: Warn when order quantity exceeds available inventory
Pattern 4: Pricing Validation
Business rule: Selling price must exceed cost plus minimum margin
Pattern 5: Data Consistency Validation
Business rule: Ensure related fields are logically consistent
Pattern 6: Threshold-Based Workflows
Business rule: High-value transactions require additional review
Pattern 7: Complex Multi-Field Validation
Business rule: Validate complex business calculation
Condition Optimization Strategies
Strategy 1: Minimize Linked Table Access
Only link tables that are necessary:
When to link tables:
Condition formula references fields from linked table
Action message displays linked table values
Business logic requires cross-table comparison
When NOT to link tables:
"Might need it later" (link when actually needed)
Only trigger table fields used in condition
Linked table only used in other conditions (link per condition if needed)
Strategy 2: Simplify Complex Calculations
Break complex formulas into multiple conditions if possible:
Benefits:
Easier to understand
Easier to maintain
Independent actions
Clearer error messages
Strategy 3: Use Appropriate Action Types
Match action type to business need:
Strategy 4: Consolidate Related Conditions
Group logically related validations in same rule set:
Benefits:
Scenarios evaluated once
Linked tables accessed once
Easier maintenance
Better performance
Strategy 5: Avoid Redundant Evaluations
Don't duplicate scenario logic in conditions:
Scenario already filtered to Document Type = Order, so condition doesn't need to check again.
Scenarios vs. Conditions: Decision Framework
When to Use Scenarios
Use scenarios when checking:
✅ Document/record type or category
Document Type = Order
Customer Type = Corporate
Item Type = Inventory
✅ Status or state
Status = Open
Blocked = No
Approved = Yes
✅ Simple field value filters
Amount > 0
Department = Sales
Region = West
✅ Date ranges for applicability
Posting Date in current fiscal year
Created Date > cutoff date
✅ User or role filters
User ID in specific list
Permission level
✅ Performance optimization
Any check that eliminates large percentage of transactions
When to Use Conditions
Use conditions when checking:
✅ Business policy enforcement
Credit limit validation
Discount authorization
Pricing rules
✅ Multi-field calculations
Amount + Balance > Limit
(Quantity * Price) > Threshold
Discount percentage calculation
✅ Cross-table comparisons
Order payment terms vs. customer default
Item price vs. cost plus margin
Salesperson commission tier
✅ Complex logical expressions
Multiple AND/OR combinations
Nested calculations
Conditional logic
✅ Validation requiring linked table data
Comparing order data to customer data
Checking item attributes
Validating against configuration tables
Decision Matrix
Check Type | Use Scenario | Use Condition | Why |
|---|---|---|---|
Document Type = Order | ✓ | Fast filter eliminates 80% of records | |
Customer Not Blocked | ✓ | Simple state check, high elimination rate | |
Amount > 0 | ✓ | Simple filter, eliminates edge cases | |
Amount + Balance > Limit | ✓ | Calculation involving linked table | |
Discount % > 15% | ✓ | Business rule requiring calculation | |
Status = Open | ✓ | Simple state filter | |
Price < Cost * 1.20 | ✓ | Business logic with calculation | |
Dept = Sales or Marketing | ✓ | Simple categorical filter | |
Payment Terms ≠ Default | ✓ | Business validation comparing fields |
The Gray Area: Could Be Either
Some checks could reasonably be scenarios OR conditions:
Example: Amount threshold
Decision guide:
Performance concern: Make it a scenario
Business logic: Make it a condition
Filters transaction applicability: Scenario
Determines rule firing: Condition
Common Mistakes and How to Avoid Them
Mistake 1: Putting All Logic in Conditions
Problem:
Issues:
Poor performance (evaluates full logic on ALL transactions)
Difficult to read and maintain
Mixing filtering with business logic
Solution:
Mistake 2: Overly Complex Scenarios
Problem:
Issues:
Defeats purpose of scenarios as fast filters
Complex calculation in every transaction
Should be in condition
Solution:
Mistake 3: Duplicating Logic Between Scenarios and Conditions
Problem:
Issues:
Redundant evaluation of Document Type
Unnecessary complexity in condition
Solution:
Mistake 4: Wrong Operator Precedence
Problem: Mixing AND/OR without clear logic structure
Solution:
Mistake 5: Not Testing Scenario Effectiveness
Problem: Adding scenarios without verifying they actually filter transactions
Solution:
Review Validation Log over representative period
Check how many transactions pass vs. fail scenarios
Adjust scenarios if filtering is ineffective
Remove scenarios that aren't filtering anything
Testing Scenarios and Conditions
Testing Scenarios
Objective: Verify scenarios correctly filter transactions
Test approach:
1. Create transactions matching scenarios:
Should see rule set in Validation Log
Scenarios show as Passed
Conditions evaluated
2. Create transactions NOT matching scenarios:
Should see rule set in Validation Log
Scenarios show as Failed
Conditions NOT evaluated
No actions executed
3. Check Validation Log columns:
Formula Type: Scenario
Formula: The scenario formula
Result: TRUE or FALSE
Formula Result: Pass or Fail
Example test:
Testing Conditions
Objective: Verify conditions correctly evaluate business logic
Test approach:
1. Create transactions where condition should be TRUE:
Actions should execute
Appropriate message/email/assignment occurs
2. Create transactions where condition should be FALSE:
Actions should NOT execute
Transaction proceeds normally
3. Test edge cases:
Boundary values
Null/empty values
Zero amounts
Maximum values
Example test:
Validation Log Analysis
Key columns for troubleshooting:
Scenario evaluation:
Formula Type = "Scenario"
Formula = scenario expression
Result = TRUE or FALSE
Formula Result = "Pass" or "Fail"
Condition evaluation:
Formula Type = "Condition"
Formula = condition expression
Result = TRUE or FALSE
Formula Result = evaluated result value
Debugging workflow:
Find transaction in Validation Log
Check if rule set appears → If not, wrong table/event or rule disabled
Check Scenario results → If failed, scenarios too restrictive or formula error
Check Condition results → If not as expected, formula error or linked table issue
Check Action results → If condition true but no action, action disabled or configuration error
Performance Tuning: Scenarios and Conditions
Performance Measurement
Baseline:
Note transaction processing time WITHOUT rules
Enable rule set
Note transaction processing time WITH rules
Calculate delta = overhead from rules
Target: <100ms additional latency per transaction for well-designed rules
Tools:
Validation Log (shows execution times if available)
Business Central Performance Profiler
User feedback on perceived slowness
Optimization Techniques
Technique 1: Maximize Scenario Filtering
Goal: Filter out 80-90% of transactions at scenario level
How:
Review transaction distribution
Add scenarios that eliminate large percentages
Order scenarios by selectivity
Measurement:
Technique 2: Minimize Linked Tables
Each linked table adds overhead:
Table relationship lookup
Filter application
Field access
Optimization:
Technique 3: Simplify Formulas
Complex calculations impact performance:
Technique 4: Consolidate Rule Sets
Multiple rule sets on same table = multiple evaluations
Before:
After:
Conclusion
The two-tier validation model—Scenarios and Conditions—is one of QUALIA Rule Engine's most powerful features. Understanding when and how to use each tier transforms rule performance from acceptable to exceptional.
Key principles:
Scenarios are filters:
Quickly identify relevant transactions
Simple, fast comparisons
Eliminate 80-90% of transactions
Combined with AND logic
Focus on applicability, not business logic
Conditions are business rules:
Implement specific policies
Can be complex calculations
Reference linked tables
Independent evaluations
Focus on business logic, not filtering
Design approach:
Start with scenarios: What makes a transaction relevant?
Add conditions: What business rules apply to relevant transactions?
Test both tiers: Verify filtering and logic separately
Optimize: Order scenarios, minimize linked tables, simplify formulas
Monitor: Review Validation Log to assess effectiveness
Performance formula:
By mastering the strategic use of scenarios and conditions, you create business rules that are not only functionally correct but also performant at scale, maintainable over time, and clear in purpose and design.
Related Reading:
Understanding Trigger Events: How Business Rules Know When to Execute
Performance Tuning Your Business Rules: A Complete Optimization Guide
The Complete Guide to Placeholders in Business Rules
Advanced Formula Techniques: Complex Business Logic Made Simple
0 Code Rule Engine
>
What is Business Rules Management and Why Your Business Needs It
>
QUALIA Rule Engine: The Complete Introduction for Business Central Users
>
Business Rules vs. Custom Code: Which Approach is Right for You?
>
Understanding Trigger Events: How Business Rules Know When to Execute
>
Scenarios vs. Conditions: Mastering the Two-Tier Validation Model
>
The Complete Guide to Placeholders in Business Rules
>
Understanding Rule Sets and Rule Organization
>
Glossary & Index
>
5 Signs Your Business Central Environment Needs a Rules Engine
>
Understanding the Business Rules Lifecycle: From Design to Deployment
Related Posts
Glossary & Index
This section provides definitions of key terms and concepts used throughout this manual.
Understanding Rule Sets and Rule Organization
Imagine opening a filing cabinet where documents are thrown in randomly—no folders, no labels, no organization. Finding what you need would be frustrating and time-consuming. Now imagine that same cabinet with clearly labeled folders, logical groupings, and a sensible structure. The difference is dramatic.
The Complete Guide to Placeholders in Business Rules
Imagine showing a user an error message that says: "Value exceeds limit." While technically informative, it leaves users asking critical questions: Which value? What limit? By how much? What should I do? Now imagine showing: "Credit limit exceeded. Customer ACME Corp has credit limit $50,000 but current balance $45,000 plus this order $10,000 would total $55,000, exceeding the limit by $5,000. Please reduce order amount, collect payment, or request credit limit increase."
