Skip to content

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

Adding Fork Nodes to Workflows

The Fork Node lets you branch workflow execution based on dynamic conditions.

  1. Navigate to your Martini Package and open your workflow.
  2. Click the Add Node button in the toolbar on the top left of the Workflow Designer.
  3. Select Fork from the node types.
  4. 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

  1. Click the expand icon on your Fork Node to open the Fork Panel.
  2. Click the on the top right of the Fork Panel Editor to select your preferred script language (see Supported Languages).
  3. Click Show Available Properties to view all workflow properties you can use in your expression.
  4. Click any property name to insert it into the editor.
  5. Write your expression in the Fork Panel Editor.
  6. 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
userStatus == "active"
Branches to the 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.toLowerCase()
Branches to the label matching the lowercase value of paymentMethod (e.g., "creditcard", "paypal").

3. Expression Returning Null

Returns null if a property is missing or empty.

1
userEmail ? userEmail : null
Branches to the $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):

  1. Select the Fork Node.
  2. Click Add Case.
  3. Remove the placeholder name to reveal dropdown options for $null and $else, or enter your expected return value.
  4. 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 $null and $else fork cases are not included by default. To add them, click Add Case and remove the placeholder name; dropdown options for $null and $else will 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:

  1. 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 true and false fork 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:

  1. Add the workflow nodes you want to run for each branch.
  2. 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.

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:

  1. Evaluate Expression: The Fork Node runs the configured expression.
  2. Select Branch of Nodes to Execute:

    • If the expression returns true or false, the Fork Node executes all nodes connected by edges to the true or false label, 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 $null label (if added; see Adding a Case Label).
    • If no matching label is found, the Fork Node executes all nodes connected to the $else label (if added; see Adding a Case Label).
    • If no labels match the expression's return value, no nodes are executed.
  3. Execution Flow: Only the branch of nodes connected to the matching fork case runs, similar to a single case block in a Java switch statement.

Best Practices

  • Case Matching: Ensure fork cases cover all possible outcomes.
  • Default Handling: Always include a $else fork case connected to a branch of nodes meant for handling unexpected values.
  • Null Handling: Add a $null fork case and connect it to a branch of nodes to handle cases where the expression may return null. 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