Create a SWITCH Statement

A SWITCH Statement evaluates a given statement against several possible results. Depending on which of the specified results is TRUE, the Bot performs different actions.

In essence, a SWITCH Statement evaluates a given statement against several IF Statements.

SWITCH Statement with three possible results

Elements of a SWITCH Statement

A SWITCH Statement consists of the following elements:

Element

Description

Control expression

The statement you want to compare to a possible result. You can use any Value Expression.

Case

A Case is a possible result. The Bot checks if it equals the Control Expression.

You can use one of the following Case types:

  • A text, a number, or another Value Expression.

  • If the data type in the Control Expression is a string: an asterisk * to indicate "If none of the other Cases are true, do this."

Step

Action that the Bot performs if a Case is TRUE.

Special characters and wildcards

RPA Studio supports special characters and wildcards in Control Expressions and Cases. For information on how to use them, see "Use special characters" and "Use wildcards".

Add a SWITCH Statement to your Bot

To add a SWITCH Statement to your Bot, follow the steps below:

  1. In the Flowchart tab, click on Add.

  2. In the Logic tab of the subsequent dialog, click on SWITCH Statement.

  3. In the Flowchart, enter your statement into the <expression> entry field.

  4. Set an appropriate data type for the Control Expression and the Cases.

    To do so, go to the Details tab and select one of the following options from the DataType drop-down menu:

    • String to process a string

    • Date to process date values

    • Numeric to process numbers

Select a data type for the Control Expression

  1. Enter your first possible result into the <case> entry field.

  2. Define what the Bot should do if it is TRUE.

    To do so, click on Add in the Yes path. You can use a Module to create this Step, or you can add another Logic element.

  3. Define what the Bot should do if the first Case is FALSE, i.e. add another Case:

    • Click on Add in the No path.
    • Enter a possible result into the <case> entry field.
    • Add Steps to your Case.
  4. Repeat to create as many Cases as needed.

Let's say your Bot needs to perform an additional set of actions on specific days.

In this case, you could use a SWITCH statement with Date Expressions:

  • The first Case checks whether the current date is the first day of the month. If this is true, the Bot performs the Steps you defined for this Case.

    If not, the Bot moves on to the second Case.

  • The second Case checks whether the current date is the last day of the month. If this is true, the Bot performs the Steps of this Case. If not, the Bot moves on.

  • The third Case checks whether the current date is the first day of the quarter. If this is true, the Bot performs the Steps you defined for this Case.

SWITCH Statement with date values

If none of the Cases are true, the Bot follows the No path and performs the Steps you defined after the SWITCH Statement.

Was this information helpful?

Tricentis RPA Studio Manual 2020.2 © Tricentis GmbH