Switch Activity

Purpose: Evaluate a set of case conditions and schedule the activity for a matching case. This activity provides multi-way branching similar to a switch/case statement in programming languages.

Input Properties

Cases

The cases to evaluate. Each case has a label, condition, and associated activity.

Type: ICollection<SwitchCase>

Default: Empty collection

Required: Yes

Note: Add cases using the switch editor. Each case contains a condition expression and an activity to execute.

Mode

The switch mode determines whether the first match should be scheduled, or all matches.

Type: SwitchMode

Default: MatchFirst

Required: Yes

Valid Values:

  • MatchFirst - Execute only the first matching case (default)
  • MatchAll - Execute all matching cases in parallel

Output Properties

Output

The value being switched on, made available as output for capturing.

Type: object

Note: Optional output that can capture the value being evaluated in the switch cases.

Port Properties

Default

The default activity to schedule when no case matches.

Type: IActivity

Note: Optional. Connect an activity to execute when none of the cases match their conditions.

Usage Example

Scenario: Route based on status value

Configuration:
- Cases:
  1. Label: "Pending", Condition: "{{ Variables.Status == 'Pending' }}", Activity: ProcessPending
  2. Label: "Approved", Condition: "{{ Variables.Status == 'Approved' }}", Activity: ProcessApproved
  3. Label: "Rejected", Condition: "{{ Variables.Status == 'Rejected' }}", Activity: ProcessRejected
- Mode: MatchFirst
- Default: HandleUnknownStatus

Result:
- The first matching case executes its associated activity
- If no cases match, the Default activity executes
- Only one path is taken (when Mode is MatchFirst)

Important Notes

  • Cases are evaluated in order until a match is found (when Mode is MatchFirst)
  • When Mode is MatchAll, all matching cases execute in parallel
  • Each case has a condition expression that must evaluate to true
  • The Default case is optional - if not provided and no cases match, the switch completes
  • Use Switch for multiple conditional branches (more than If/Else)
  • For simple true/false branching, use If activity instead
  • Case conditions can use any valid Elsa expressions

Related Activities