Tutorials
Check whether enough material is available before work can continue. The example turns that business decision into a rule you can create, evaluate and inspect.
Learn how to create a GUARD rule that prevents work orders from being released to production when required materials are not available in inventory. This tutorial demonstrates condition building, action configuration, and testing.
Problem: Work orders are sometimes released to the shop floor before all required materials are available, causing production delays and resource waste.
Solution: Create a business rule that checks material availability and blocks the status change if materials are not ready.
Rule Behavior:
business_rules.rules.create permissionThe rule creation form will open.
Configure the rule's core properties.
Rule ID:
BLOCK_WO_RELEASE_WITHOUT_MATERIALS
Rule Name:
Block Work Order Release Without Materials
Description:
Prevents work orders from being released to production when required
materials are not available in inventory. This ensures production
schedulers have visibility into material constraints before committing
resources to the work order.
Rule Type: Select GUARD
π‘ GUARD rules are designed to block or allow operations. They're perfect for this use case.
Rule Category:
Material Planning
Entity Type:
WorkOrder
Event Type:
onStatusChange
βΉοΈ The
onStatusChangeevent triggers when the work order status field changes. This is more specific thanbeforeUpdatewhich fires on any field change.
Configure execution settings.
Priority: 800
π‘ High priority (500-1000) ensures this guard rule executes before other validation or action rules.
Enabled: β Checked
Version: 1
Effective From: Leave empty (active immediately)
Effective To: Leave empty (no expiration)
Define when the rule should block the operation.
We want to block when:
Click Add First Condition to begin.
Field: newStatus
Operator: = (equals)
Value: "RELEASED"
βΉοΈ The
newStatusfield represents the status the user is trying to change to. This field is provided by theonStatusChangeevent.
Click Add Condition to add a second condition to the AND group.
Field: materialsAvailable
Operator: = (equals)
Value: false
βΉοΈ This assumes your work order entity has a
materialsAvailableboolean field. Adjust the field path based on your data model. You might usematerials.available,materialStatus, or a calculated field.
If you don't have a boolean flag, you can check quantities:
AND Group:
- newStatus = "RELEASED"
- requiredQuantity > availableQuantity
Or check for zero inventory:
AND Group:
- newStatus = "RELEASED"
- availableQuantity <= 0
Your condition builder should show:
AND Group (2 rules):
- newStatus = "RELEASED"
- materialsAvailable = false
This reads as: "Block when new status is RELEASED and materials are not available."
Set up what happens when conditions match.
For GUARD rules:
This might seem counterintuitive at first! Think of it as:
These execute when we want to block the release.
Navigate to the Failure Actions section and click Add Action.
Type: Select BLOCK_TRANSITION
Configuration: No configuration needed
π‘ This action prevents the status change from occurring.
Click Add Action again.
Type: Select SHOW_ERROR
Message:
Cannot release work order. Required materials are not available in inventory. Please verify material availability and try again.
π‘ Clear, actionable error messages help users understand what went wrong and how to fix it.
Click Add Action again.
Type: Select NOTIFY
Recipients:
[email protected], [email protected]
βΉοΈ Replace with actual email addresses or user IDs from your system.
Message:
Work order {{workOrderId}} cannot be released due to material unavailability. Status: {{status}}, Required materials: {{requiredMaterials}}
π‘ Use
{{field}}syntax to include dynamic data in notification messages.
Click Add Action once more.
Type: Select LOG
Level: Select warn
Message:
Blocked work order {{workOrderId}} release due to material unavailability. Requested by {{user.email}}
Leave the Success Actions section empty.
When materials ARE available (conditions are false), the rule succeeds and allows the operation without taking any action.
The rule is now active and will begin evaluating work order status changes immediately.
Test the rule to ensure it works as expected.
Using the API:
curl -X POST "$BASE_URL/api/business_rules/execute" \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"entityType": "WorkOrder",
"entityId": "wo-test-001",
"eventType": "onStatusChange",
"data": {
"workOrderId": "wo-test-001",
"oldStatus": "PENDING",
"newStatus": "RELEASED",
"materialsAvailable": false,
"requiredMaterials": "Steel plates, bolts"
},
"dryRun": true
}'
Expected Response:
{
"allowed": false,
"executedRules": [
{
"ruleId": "BLOCK_WO_RELEASE_WITHOUT_MATERIALS",
"result": "FAILURE",
"conditionResult": true,
"message": "Cannot release work order. Required materials are not available..."
}
]
}
Success: The rule blocked the operation as expected.
curl -X POST "$BASE_URL/api/business_rules/execute" \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"entityType": "WorkOrder",
"entityId": "wo-test-002",
"eventType": "onStatusChange",
"data": {
"workOrderId": "wo-test-002",
"oldStatus": "PENDING",
"newStatus": "RELEASED",
"materialsAvailable": true
},
"dryRun": true
}'
Expected Response:
{
"allowed": true,
"executedRules": [
{
"ruleId": "BLOCK_WO_RELEASE_WITHOUT_MATERIALS",
"result": "SUCCESS",
"conditionResult": false
}
]
}
Success: The rule allowed the operation when materials are available.
curl -X POST "$BASE_URL/api/business_rules/execute" \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type": application/json" \
-d '{
"entityType": "WorkOrder",
"entityId": "wo-test-003",
"eventType": "onStatusChange",
"data": {
"workOrderId": "wo-test-003",
"oldStatus": "PENDING",
"newStatus": "IN_PROGRESS",
"materialsAvailable": false
},
"dryRun": true
}'
Expected Response:
{
"allowed": true,
"executedRules": [
{
"ruleId": "BLOCK_WO_RELEASE_WITHOUT_MATERIALS",
"result": "SUCCESS",
"conditionResult": false
}
]
}
Success: The rule didn't block because the status is not "RELEASED".
After testing, check the execution logs:
ruleId: BLOCK_WO_RELEASE_WITHOUT_MATERIALSYou should see three log entries from your tests showing:
Instead of a boolean flag, check individual material items:
AND Group:
- newStatus = "RELEASED"
OR Group:
- materials[0].quantity < materials[0].required
- materials[1].quantity < materials[1].required
Use SHOW_WARNING instead of BLOCK_TRANSITION:
Failure Actions:
- SHOW_WARNING: "Some materials are below minimum quantity"
- LOG: warn, "Partial material availability for {{workOrderId}}"
Add condition for lead time:
AND Group:
- newStatus = "RELEASED"
OR Group:
- materialsAvailable = false
- materialLeadTime > daysUntilRequired
Set a flag requiring manager approval when materials are short:
Failure Actions:
- SET_FIELD: approvalRequired = true
- SET_FIELD: approvalReason = "Material shortage"
- NOTIFY: [email protected], "Approval needed for {{workOrderId}}"
- ALLOW_TRANSITION (allow but flag for review)
Check:
Check:
Check:
Check:
Now that you've built your first GUARD rule:
You've successfully created a GUARD rule that:
Prevents work order release when materials are unavailable β Shows clear error messages to users β Notifies the material planning team β Logs all blocked attempts for audit trail β Allows release when materials are ready
This rule helps prevent production delays by ensuring material availability before committing resources to work orders.
Previous: Building a Todo Module with Custom Fields Β· Next: Devices & Push Notifications β Getting Started