If Activity
Purpose: Evaluate a Boolean condition to determine which activity to execute next. This activity provides conditional branching in workflows.
Input Properties
The Boolean condition to evaluate. If true, the Then activity is executed; if false, the Else activity is executed.
Type: bool
Default: false
Required: Yes
Note: Can be a literal boolean, expression, or variable reference. Supports all Elsa expression syntaxes.
Output Properties
The result of the condition evaluation (true or false).
Type: bool
Note: This output contains the evaluated condition value, which can be used by subsequent activities.
Port Properties
The activity to execute when the condition evaluates to true.
Type: IActivity
Note: Connect the activity you want to execute when the condition is true.
The activity to execute when the condition evaluates to false.
Type: IActivity
Note: Connect the activity you want to execute when the condition is false. This is optional - if not provided, the workflow continues to the next activity when the condition is false.
Usage Example
Scenario: Check if a value is greater than 10 and execute different paths
Configuration:
- Condition: "{{ Variables.Count > 10 }}"
- Then: Connect to WriteLine activity with text "Count is high"
- Else: Connect to WriteLine activity with text "Count is low"
Result:
- If Count > 10: "Count is high" is written
- If Count <= 10: "Count is low" is written
- Result output contains the boolean evaluation result
Important Notes
- The condition is evaluated once at the start of the activity
- Only one path (Then or Else) is executed based on the condition result
- The Else port is optional - if not connected, execution continues normally when condition is false
- You can use complex expressions in the Condition property
- The Result output can be used by subsequent activities to know which path was taken
- For multiple conditions, consider using the Switch activity instead
Related Activities
- Switch - Evaluate multiple case conditions (for multiple branches)
- FlowDecision - Flowchart version of If activity
- SetVariable - Set variables that can be used in condition expressions