Martini Workflows Fork Node
Overview
The Fork Node is a control flow feature in Martini Workflows that lets you route execution to different branches of workflow nodes based on evaluated conditional expressions. It works like a Java switch statement, helping you organize decision logic in one place and making workflows easier to read, debug, and extend.
Fork Nodes in workflows function similarly to Fork Steps in services, allowing you to split execution into multiple branches based on the result of an expression.
What You Will Learn
- How to configure and use the Fork Node for conditional branching
- How to set up fork cases and handle default/null cases
When to Use This
Use this when you need to:
- Route workflow execution based on the value of a variable or expression
- Implement multi-path decision logic within a workflow
- Implement if/else type logic with a clear branching structure
Prerequisites
- Martini Designer installed and running
- Create a Martini Package
- Create a Workflow
- Basic understanding of how to use Workflow Designer
Adding Fork Nodes to Workflows
The Fork Node lets you branch workflow execution based on dynamic conditions.
- Navigate to your Martini Package and open your workflow.
- Click the Add Node button in the toolbar on the top left of the Workflow Designer.
- Select Fork from the node types.
- Drag the Fork Node to your desired position in the workflow.
Expected result: The Fork Node appears in your workflow, ready for configuration.
Setting a Conditional Expression
Conditional expressions let you dynamically determine which branch the workflow should follow. Use them to evaluate properties, perform checks, or compute values that control workflow routing.
Configure Fork Expression
- Click the expand icon on your Fork Node to open the Fork Panel.
- Click the on the top right of the Fork Panel Editor to select your preferred script language (see Supported Languages).
- Click Show Available Properties to view all workflow properties you can use in your expression.
- Click any property name to insert it into the editor.
- Write your expression in the Fork Panel Editor.
- Close the Fork Panel by clicking the X icon when done.
Expected result: The Fork Panel closes and your expression is saved.
Fork Expression Examples
Refer to Fork Cases for details on how expression results map to workflow branches.
1. Boolean Expression
Returns true or false to branch to the corresponding fork case.
1 | |
true label if userStatus is "active", otherwise to false.
2. Plain Text or Value Expression (for Add Case)
Returns a specific value to match an "Add Case" label.
1 | |
paymentMethod (e.g., "creditcard", "paypal").
3. Expression Returning Null
Returns null if a property is missing or empty.
1 | |
$null label if userEmail is missing or empty.
Supported Languages
Martini supports multiple scripting languages for Script Nodes. The available options are:
- Groovy (default)
- Batch
- Python (option appears if installed)
- JavaScript (option appears if installed)
Configuring Fork Node Conditional Branches
Understanding Fork Cases
Fork cases clarify the logic of each connection from the Fork Node, similar to cases in a Java switch statement.
| Label | When Used | What Happens |
|---|---|---|
| true | Expression returns true |
Executes connected node(s) |
| false | Expression returns false |
Executes connected node(s) |
| Add Case | Use this to create a branch for any specific value your expression might return | Executes the node(s) connected to this label when the expression matches that value. See Adding a Case Label for details. |
| $null | Expression returns null |
Executes node(s) for a null value. Must be added via Add Case. |
| $else | No other label matches | Executes node(s) when the expression result does not match any other fork case in the Fork Node. Must be added via Add Case. |
How to Add A Fork Case
To add a fork case (including $null and $else):
- Select the Fork Node.
- Click Add Case.
- Remove the placeholder name to reveal dropdown options for
$nulland$else, or enter your expected return value. - Press Enter.
Expected result: The new fork case on the right side of the Fork Node, ready for you to create a workflow edge from it and connect to other workflow nodes.
Note: The
$nulland$elsefork cases are not included by default. To add them, click Add Case and remove the placeholder name; dropdown options for$nulland$elsewill appear for easy selection.Important: You cannot add duplicate fork cases—each fork case must be unique.
How to Delete A Fork Case
To delete a fork case:
- Select the Fork Node Click the X icon next to any fork case.
Expected result: The fork case is removed from the Fork Node. Any edges connected to that fork case are also removed, and connected nodes become disconnected.
Note: The
trueandfalsefork cases are included by default, but you can delete them if your workflow does not require boolean branching.
Connecting Nodes to Fork Cases
On the right of the Fork Node, you will see your Fork Cases represented by edge labels:
- Add the workflow nodes you want to run for each branch.
-
Create edges to connect each node to the appropriate fork case. See Fork Cases. For example:
- true: Connect this label to the node(s) to execute if the expression returns
true. - false: Connect this label to the node(s) to execute if the expression returns
false. - Add Case: Add cases for specific values you expect (similar to Java's
switch case. Connect each case label to the appropriate node(s). See Adding a Case Label.
- true: Connect this label to the node(s) to execute if the expression returns
Expected result: Your workflow now branches conditionally based on the Fork Node's expression.
Fork Node Runtime Behavior
When activated, the Fork Node evaluates its expression and selects which branch of nodes to execute, based on the connected fork cases:
- Evaluate Expression: The Fork Node runs the configured expression.
-
Select Branch of Nodes to Execute:
- If the expression returns
trueorfalse, the Fork Node executes all nodes connected by edges to thetrueorfalselabel, respectively. - If the expression returns a specific value, the Fork Node executes all nodes connected by edges to the label matching that value (if added; see Adding a Case Label).
- If the expression returns
null, the Fork Node executes all nodes connected to the$nulllabel (if added; see Adding a Case Label). - If no matching label is found, the Fork Node executes all nodes connected to the
$elselabel (if added; see Adding a Case Label). - If no labels match the expression's return value, no nodes are executed.
- If the expression returns
-
Execution Flow: Only the branch of nodes connected to the matching fork case runs, similar to a single
caseblock in a Javaswitchstatement.
Best Practices
- Case Matching: Ensure fork cases cover all possible outcomes.
- Default Handling: Always include a
$elsefork case connected to a branch of nodes meant for handling unexpected values. - Null Handling: Add a
$nullfork case and connect it to a branch of nodes to handle cases where the expression may returnnull. This ensures your workflow gracefully manage missing or empty values.
Why It Matters
The Fork Node streamlines complex decision logic, making workflows easier to maintain and extend. By centralizing branching, you reduce errors and improve clarity, especially when handling multiple outcomes.
Troubleshooting
| Problem | Detection | Cause | Fix | Affected Versions |
|---|---|---|---|---|
| Branch of nodes not executed | Workflow does not produce expected results | No matching fork case, or the fork case is not connected to the correct branch of nodes | Add a $else or $null fork case and connect it to a branch of nodes for fallback handling. Consider adding logging or checks to help diagnose missing or unexpected values. |
v2.x+ |
Helpful Resources
- Java
switchstatement - Fork Step
- Workflow Designer
- Martini Package Creation
- Create a Workflow
- Workflow Nodes
- Community Q&A: Martini Community
Have a Question? Post or search it here.