FlexiRule Docs
Recipe: Validate and Block Document Submission
Learn how to build visual validation guardrails that enforce business rules using the Smart Value Selector and Stop / Error actions.
Recipe: Validate and Block Document Submission#
In ERPNext, business rules frequently require blocking document submission when critical conditions are not met—such as when an invoice exceeds a budget limit without an assigned project code.
In this recipe, you will visually configure a rule that evaluates document criteria using the Smart Value Selector and blocks submission with a custom error popup.
Scenario Overview#
Business Goal: Prevent submission of a Purchase Invoice if the invoice amount exceeds 50,000 and no Project is assigned.
- Target DocType:
Purchase Invoice - Trigger Event:
DocType Event->Before Submit - Visual Nodes:
Start->Check->Stop / Error
Step-by-Step UI Instructions#
Step 1: Create the Rule Document#
- Navigate to FlexiRule -> Rule List -> New.
- Set Rule Name to
PI - Enforce Project on Large Invoices. - Set Document Type to
Purchase Invoice. - Set Trigger Type to
DocType Event. - Set Trigger Event to
Before Submit. - Click Save, then click Open Rule Builder.
Step 2: Configure the Check (Condition) Node#
Hover over the Start node and click + Add Action.
Select Check (Condition) from the action menu.
In the Check configuration panel on the right:
- Set Group Logic to ALL.
- Click Add Condition.
Configure Condition 1 (Grand Total Check):
- Click the left value field.
- Type
@to open the Smart Value Selector. - Search for
Grand Totalin the search popup. - Select Purchase Invoice → Grand Total.
- Set the Operator dropdown to Is Greater Than.
- In the right value field, enter
50000.
Configure Condition 2 (Project Assignment Check):
- Click Add Row to add a second condition.
- Click the left value field and type
@to open the Smart Value Selector. - Search for
Projectin the search popup. - Select Purchase Invoice → Project.
- Set the Operator dropdown to Is Not Set.
Step 3: Add and Configure the Stop / Error Node#
- From the True (Green) outbound port of the Check node, drag a connection to a new node position.
- Select Stop / Error from the action picker.
- In the Stop / Error configuration panel:
- Set Mode to
Error (Raise Validation Error). - Set Title to
Missing Project Assignment. - Click inside the Error Message editor field.
- Type
Purchase Invoice. - Type
@to open the Smart Value Selector, search forName, and select Purchase Invoice → Name. - Type
with total amount of. - Type
@again, search forGrand Total, and select Purchase Invoice → Grand Total. - Append
exceeds 50,000 and requires a Project code before submission..
- Set Mode to
Step 4: Verify with Visual Debugger#
- Click Test Run in the top action bar.
- In the Test Run dialog, select a Purchase Invoice record with a Grand Total above 50,000 and no Project assigned.
- Click Run Test.
- Observe the visual execution path highlighted on the canvas terminating at the Stop / Error node, confirming that invalid submissions will be blocked.
Key Takeaways#
- Visual Field Selection: Use
@or click the Variable (@) button in any input field to select document fields interactively. - Transaction Rollback: Raising an error in
Before Submitautomatically rolls back the database transaction, keeping your data clean.
Was this page helpful?