Create an IF Statement

An IF Statement checks whether a given statement is TRUE or FALSE. Depending on the outcome, the Bot performs different actions.

An IF Statement consists of the following elements:

Element

Description

Control Expression

Statement that the Bot should check.

Then

Steps that the Bot performs if the statement is TRUE.

Else

Steps that the Bot performs if the statement is FALSE.

You don't have to define both a Then and an Else. You can also specify just one of the two.

Work with Control Expressions

A Control Expression is a statement that the Bot should verify.

Typically, this statement consists of the following elements:

  • a Value Expression that you compare with the help of

  • an operator (==, !=, <, >, <=, or >=) to

  • a text, a number, or another Value Expression

For instance: {B[Total]} >= 30 checks whether the value of the Buffer Total equals or exceeds 30.

Whenever you work with numbers or dates, ensure that you have set the correct date and number format for RPA Studio.

Use Modules in Control Expressions

Alternatively, you can use a Module in the Control Expression, provided that the resulting Step contains a verification.

For instance, you can use the Module File Existence from the RPA subset to check whether a certain file exists (see the example below). Depending on the outcome of the check, the Bot performs different actions.

To add a Module to a Control Expression, click on Add within the Control Expression and select a Module in the subsequent dialog.

Add a Module to a Control Expression

You can also drag and drop an existing, filled-out Step onto the Control Expression, provided that this Step was created from a Module.

To remove the Module, click on the Control Expression and delete the Module from the Details tab.

If you want to use the Module in a different place in your Flowchart, drag and drop it from the Details tab into the Flowchart.

Module in a Control Expression

Special characters and wildcards

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

Add an IF Statement to your Bot

To add an IF Statement, follow the steps below:

  1. In the Flowchart tab, click on Add.

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

  3. In the Flowchart, define the statement that the Bot should verify. To do so, enter your statement into the <expression> entry field.

    Alternatively, use a Module as described above: "Use Modules in Control Expressions".

  4. If you don't use a Module, set an appropriate data type for the Control Expression.

    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. Specify a Then and/or an Else:

    • To define what the Bot should do if the statement is TRUE, click on Add in the Yes path of the IF Statement.

    • To define what the Bot should do if the statement is FALSE, click on Add in the No path of the IF Statement.

    You can use a Module to create this Step, or you can add another Logic element.

This example shows how to save a number that is part of a text in a Label. Next, you want to verify this number in an IF Statement.

The Step Save order total, uses an XBuffer to do the following things:

  • It verifies whether the text in the Label is the expected text.
  • It saves the money amount into a Buffer called Total.

Dynamic comparison with XBuffer

The Control Expression in the IF Statement verifies whether the value in the Buffer equals 130.50.

Bot flow with IF Statement

This example shows how to use a Module in an IF Statement.

Let's say your Bot goes through a lengthy process. At the end of this process, it creates a file. You want to check whether the Bot has created the file in the right directory. Depending on the outcome of this check, the Bot should perform different actions.

To create the check, follow the steps below:

  1. Add the IF Statement.

  2. Click on Add within the Control Expression.

  3. In the subsequent dialog, select the Module File Existence. This Module is part of the RPA subset.

  4. Fill out the Step Values. In this case, you want to check the existence of the file Example.txt at C:\Temp.

Verify the existence of a file

  1. Define the action(s) you want the Bot to perform if the file exists, i.e. the statement is TRUE. Optionally, add an Else.

IF Statement with Module: Control Expression in the Flowchart and in the Details tab

Was this information helpful?

Tricentis RPA Studio Manual 2020.2 © Tricentis GmbH