NF13 Support Model Validation on Workflow Node Entry
From iDempiere en
NF13 Support Model Validation on Workflow Node Entry
NOTE: This is not yet integrated into core
Goal: Technical
Developer: Deepak Pansheriya Logilite Technologies
Feature Ticket: IDEMPIERE-6548
Background
In iDempiere, workflow transitions between nodes—specifically User Task or User Choice nodes—generally do not trigger model validation events. This limits the ability to enforce business rules or data integrity checks precisely at workflow step changes.
Problem
- No Validation on Node Entry: Currently, model validators are not invoked when entering workflow nodes such as User Task or User Choice.
- Limited Business Rule Enforcement: It is difficult to enforce rules that must be checked exactly when the workflow moves into a new state.
Solution: Model Validation Event on Workflow Node Entry
A new event, TIMING_BEFORE_WF_NODE_EXECUTION, is introduced. This event is fired before execution of workflow node type of User Task or User Choice.
This enables standard model validator hooks to implement validation on execution of custom nodes:
- Validate data and business logic before node marked processed.
- Block workflow progression if validation fails.
- Optionally modify data during validation.
Behavior
- The event triggers for all persistent objects (PO) involved in workflows.
- If the validator returns an error message, the workflow does not proceed to the next node.
- Validators can implement logic based on node type or document state.
- Existing validators must be updated to handle this new event type distinctly.
Automated Testing
Covered by org.idempiere.test.event.WorkflowNodeModelEventTest
, which:
- Verifies that the event fires on User Task and User Choice nodes.
- Tests validation success and failure cases.
- Simulates modification of PO fields during validation.
Example Usage
public class MyValidator implements ModelValidator {
@Override
public String docValidate(PO po, int timing) {
if (timing == ModelValidator.TIMING_BEFORE_WF_NODE_EXECUTION) {
// Example validation logic
if ("Invalid".equals(po.get_ValueAsString("DocumentStatus"))) {
return "Document status is invalid for this workflow step.";
}
}
return null;
}
}