- Customization & development
Rules engine introduction
The OrderCloud platform now includes a rules engine, initially powering order approval workflows. This system executes externally defined rules to extend platform behavior, similar to how extended properties (XP) extend the data model.
Rules engine concepts
Rule definition
A rule consists of:
- If-then statement
- External logic definition
- Custom expressions
- Defined actions
Platform integration
OrderCloud provides:
- Action definitions
- Execution environment
- Expression evaluation
- Rule management
Implementation example
Approval workflow
Create an order approval rule:
- Create manager
UserGroup - Create
ApprovalRule - Set
ApprovingGroupID - Define expression:
javascript
Expression components
Available properties:
order: Matches Order model- Includes extended properties
Supported operators:
- Comparison:
=,<,<=,>=,<> - Logical:
and,or,not - Mathematical:
+,-,*,/
Value formatting:
- Strings: Single quotes
- Dates:
#6/15/2016# - Parentheses: Group expressions
Line item operations
Collection functions
The rules engine provides collection functions for line item evaluation:
Cost center example
javascript
Available functions
items.any: Any item matches filteritems.all: All items match filteritems.quantity(): Sum of matching quantitiesitems.count(): Number of matching itemsitems.total: Dollar amount comparison
Multi-level approvals
Rule chaining
Check other rule approvals:
javascript
Complex approval chains
javascript
Implementation guidelines
Best practices
- Keep rules simple
- Split complex rules
- Test thoroughly
- Document clearly
Debugging tips
- Start simple
- Add complexity gradually
- Test each condition
- Verify assumptions
Future applications
Potential use cases
- Custom validation
- Time-based approvals
- Dynamic pricing
- Coupon eligibility
- Inventory management
- Webhook triggers
Platform strategy
The rules engine supports our Flexibility over Features approach by:
- Enabling customization
- Supporting business logic
- Extending functionality
- Maintaining flexibility
Related reading
If you have suggestions for improving this article, let us know!