Skip to main content

Switch

System.Activities.Statements.Switch

The "Switch" activity in AutomatR is a control flow activity that allows you to define multiple cases based on the value of an expression and execute specific actions for each case. It is a powerful tool for creating structured workflows with different outcomes based on the value of a variable or expression.

Properties

NameDescription
Misc
Display NameThe display name of the activity. A display name is automatically generated when you indicate a target.
ExpressionSpecifies the expression whose value will be evaluated to determine which case to execute. The cases are defined based on the possible values of this expression. Variables containing the expression to be evaluated. The expression can be of various types, such as integers, strings, or enums.

How to use:

  1. Drag and drop the "Switch" activity onto the workflow.
  2. In the "Expression" property, specify the variable or expression whose value will be used to determine the case to execute.
  3. Inside the "Switch" activity, define different cases based on possible values of the expression.
  4. Place the activities to be executed for each case inside the corresponding case container.

Example: Consider an example where the "Switch" activity is used to handle different payment methods:

Switch:
Display Name: "Payment Method Switch"
Expression: paymentMethod
// The expression is the variable representing the payment method
Case "Credit Card":
// Activities for processing credit card payment
Log Message: "Processing credit card payment."
Case "PayPal":
// Activities for processing PayPal payment
Log Message: "Processing PayPal payment."
Case "Bank Transfer":
// Activities for processing bank transfer
Log Message: "Processing bank transfer."
Default:
// Activities for handling other payment methods
Log Message: "Unknown payment method."

In this example, the "Switch" activity evaluates the value of the "paymentMethod" variable and executes the corresponding case based on the payment method. The "Default" case handles scenarios where the payment method is not explicitly defined in the cases.

The "Switch" activity provides a clean and organized way to handle multiple scenarios within a workflow, making it easier to read and maintain automation projects.