Business Rules
The Business Rules Engine enables you to define, manage, and execute automated business logic without writing code. Rules are evaluated when specific events occur in your system, allowing you to enforce policies, validate data, calculate values, and trigger actions automatically.
What Are Business Rules?
Business rules are conditional statements that execute actions when certain criteria are met. They follow an "if-then" logic pattern:
- IF conditions are true (e.g., order total > $1000)
- THEN execute actions (e.g., require manager approval)
Rules can be applied to any entity type in your system (Orders, WorkOrders, Customers, etc.) and triggered by lifecycle events (beforeCreate, afterUpdate, etc.).

Business Rules navigation showing Rules, Rule Sets, and Execution Logs pages
Why Use Business Rules?
Centralized Business Logic Define business policies in one place instead of scattered throughout code. Rules are easier to audit, update, and maintain.
No-Code Automation Business users and administrators can create and modify rules without developer involvement. Changes take effect immediately.
Consistent Enforcement Rules are executed automatically and consistently across all channels (UI, API, integrations). No manual checks required.
Audit Trail Every rule execution is logged with input context, output, and performance metrics. Full visibility into decision-making.
Flexible and Powerful Complex logic with nested conditions, multiple actions, field comparisons, and special values (current date, logged-in user, etc.).
Key Concepts
Rules
A rule defines when and how business logic should be executed. Each rule has:
- Basic information - Name, description, type, category
- Scope - Entity type and event type (when to trigger)
- Conditions - Logic that determines if the rule applies
- Actions - What happens when conditions are met (success) or not met (failure)
- Metadata - Priority, version, effective dates, enabled status
Rules list page showing all defined business rules with filters and actions
Rule Types
Open Mercato supports five rule types:
- GUARD - Block or allow operations (e.g., prevent work order release without materials)
- VALIDATION - Validate data before saves (e.g., require approval for large orders)
- CALCULATION - Calculate derived values (e.g., compute discount based on volume)
- ACTION - Trigger side effects (e.g., send notifications, call webhooks)
- ASSIGNMENT - Set field values automatically (e.g., auto-assign based on criteria)
Conditions
Conditions determine when a rule applies. They support:
- Field paths - Access nested data with dot notation (e.g.,
user.email,order.items[0].quantity) - Operators - 15 operators including equality, comparison, collection checks, string matching, regex
- Special values - Dynamic values like
{{today}},{{now}},{{user.id}} - Logical groups - Combine conditions with AND/OR, nest groups for complex logic
Actions
Actions define what happens when conditions pass (success actions) or fail (failure actions):
- User feedback - Display messages (errors, warnings, info)
- State control - Allow or block transitions
- Field updates - Set entity field values
- Notifications - Send notifications to users
- Logging - Write to execution logs
- Integrations - Call webhooks, emit domain events
Rule Sets
Rule sets group related rules together. They provide:
- Organization - Group rules by domain (e.g., Quality Control, Pricing)
- Execution order - Control sequence of rule execution
- Bulk management - Enable/disable entire sets at once
- Per-rule control - Enable/disable individual rules within a set
Execution Logs
Every rule execution is recorded with:
- Timestamp - When the rule was executed
- Rule details - Which rule was executed
- Entity context - What entity triggered the rule
- Result - SUCCESS, FAILURE, or ERROR
- Input/output - Data before and after execution
- Performance - Execution time in milliseconds
Logs are essential for debugging, auditing, and analytics.
Common Use Cases
Quality Control
Enforce quality standards automatically:
- Block work order completion if quality checks fail
- Require inspection for specific product types
- Validate measurements against tolerances
Approval Workflows
Route items for approval based on criteria:
- Require manager approval for orders above threshold
- Escalate to senior management for high-priority issues
- Auto-approve routine requests
Resource Management
Manage resource allocation intelligently:
- Auto-assign work orders based on skills and availability
- Block scheduling if resources are unavailable
- Warn about conflicts and capacity issues
Compliance and Safety
Enforce regulatory and safety requirements:
- Require safety certification before hazardous work
- Block operations on expired equipment
- Ensure required documentation is complete
Customer Experience
Improve customer interactions:
- Apply discounts automatically based on volume
- Send notifications at key milestones
- Escalate issues based on customer tier
Getting Started
- Create Your First Rule - Step-by-step guide to creating rules
- Build Conditions - Learn how to create complex conditional logic
- Configure Actions - Set up actions for success and failure scenarios
- Organize with Rule Sets - Group related rules together
- Monitor Execution - View logs and debug issues
Best Practices
Start Simple Begin with straightforward rules (single condition, single action) before building complex logic.
Test Thoroughly Use dry-run mode to test rules without side effects. Review execution logs carefully.
Use Descriptive Names Name rules and rule sets clearly to indicate their purpose (e.g., "Block WO Release Without Materials").
Set Appropriate Priority Higher priority rules execute first. GUARD rules should typically have high priority.
Monitor Performance Review execution logs for slow rules. Complex conditions or many rules can impact performance.
Version Control Use the version field to track changes. Consider effective dates for time-based rule changes.
Document Rules Use the description field to explain the business rationale and any special considerations.
RBAC Features
Access to Business Rules functionality is controlled by these features:
business_rules.rules.view- View rules and rule setsbusiness_rules.rules.create- Create new rulesbusiness_rules.rules.edit- Edit existing rulesbusiness_rules.rules.delete- Delete rulesbusiness_rules.rules.execute- Manually execute rulesbusiness_rules.logs.view- View execution logs
Contact your administrator to request access.
Next Steps
- Rule Types Reference - Detailed explanation of each rule type
- Creating Rules - Step-by-step rule creation guide
- API Reference - Integrate rules into your applications
- Framework Architecture - Extend the rule engine