Conditional Statements in UiPath Studio

A Condition is one of the most helpful activities to use when you have more than one solution after an action. Conditional statements specify what behavior is desired if a particular condition is met. We use the Flow Decision in the Activities panel to achieve a condition.

There two conditional statements are present in UiPath

  • If Condition
  • Switch Condition

If Condition Statement in UiPath Studio :

The If condition contains a statement and two paths, The first path will be executed if the statement is True, While the second path is executed if the statement is False. If condition activities are useful to make a decision based on the boolean value.

Example.1 :

The following example demonstrates to verify whether the given number is even or odd.

The first step is to create a sequence by the name called conditions
creating-new-sequence-called-conditions-rpa-uipath

Once the sequence has been created successfully, include Assign activity inside it and then create a variable.
drag-and-drop-assign-inside-the-sequence-rpa-uipath

You can create a variable in two ways, either you can create a variable by using variable pane or inside any activity by pressing Ctrl+K and then you can give a variable name and press enter. Hence the variable will be created as shown below
create-variable-number-rpa-uipath

The default value of the variable will be Generic, which means it can consider either Integer, Boolean, or String type, To be on the Safer side set the variable type to Int32.
set-variable-type-to-int32-rpa-uipath

Next, assign the value to the variable to check whether the given number is even or odd. I am assigning 5 as the value and then drag and drop the If condition activity inside the sequence.
drag-drop-if-condition-into-sequence-rpa-uipath

Write the condition to check given number is Even number or not as shown below and add Message box into Then and Else block and write Even and Odd as shown below
writing-condition-for-evenand-odd-rpa-uipath

Make sure to add Even and Odd inside the Then and else message box within double-quotes.

Now, save the sequence and run. Once the sequence executes, the message will be displayed as shown below.
Out-pu-of-if-statement-uipath-rpa

Now let us change the variable value to 10 and save then execute
evan-example-output-rpa-uipath

Installing/Managing Packages in UiPath Studio

Switch Condition Statement in UiPath Studio

The Switch condition statement enables you to select one choice out of multiple, based on the value of a specified expression. By default, the Switch condition uses the integer argument, but you can change it from the Properties panel, from the TypeArgument list.

The following example demonstrates the switch condition statement, If the grade is A then the output will be Excellent and if the Grade is B then the output will be Good and the default output will be Failed.

The first step is to create a sequence by the name Switch_condition_Exmaple

switch-condition-example-sequence-rpa-uipath

Add Assign activity inside the sequence and create a variable called Grade.
creating-variable-inside-assign-activity-rpa-uipath

Next, add the Switch condition activity inside the sequence and write the condition for the same. In the property pane, select the TypeArgument as String.
type-argument-rpa-uipath

Next, add the expression as Grade and the case as Default and Add the Write Line activity inside the default and enter the text as "Failed"
add-writeline-into-deafault-rpa-uipath

Next, add case as A and add Write Line activity inside the case and enter the text inside the WriteLine as "Excellent"
add-write-line-inside-case-a-rpa-uipath

Next, add a new case as B and add the Write Line activity inside case B and add the text as "Good"
add-write-line-activity-insoide-case-b-rpa-uipath

Add another case C and Write Line activity inside it and then add text as "Please Improve"
add-write-line-activity-inside-the-case-c-rpa-uipath

Now, save the sequence and run, once the sequence starts to execute the output will be Please Improve.

the-output-of-grade-rpa-uipat

If we change the Grade="D" and which does not equal to any other case and UiPath picks the default whenever there is no matching case. And the output will be Failed.

Save and run the sequence and the output will be shown as below
the-output-as-failed-rpa-uipat

PDF Automation by Using UiPath Studio

User Inputs in UiPath

In UiPath, we use Input data to store in a variable that can be used to pass data from one activity to another. Incase of If condition to check whether the given number is even or odd and in case of Switch statement the grade has been set to constants.

In automation, there are some scenarios where you need to take the inputs from the user. By using the Input Dialog activity we can accept the inputs from the user.

Example.1:

The following example demonstrates whether the given number is even or odd.

Drag and drop the Input dialog into the If condition sequence.

user-input-box-uipath

Now enter the title and the label in the input dialog activity. I am entering the title as "Input" and the label as "Enter a Number". The input dialog will take the input from the user and set it to the Number via the properties panel where you see the output.

The user input which is given as number should be taken into a variable called the Number_variable, the output result should be stored in a Number_variable.
user-input-box-2-uipath

Now, save the sequence and run, the Uipath will ask to enter the input, enter any number to check for even or odd. Enter the 12 and Click on Ok.
input-dialog-box-uipath

The output will be shown as below
message-result-uipath-even

Example.2:

The Following example demonstrates Managing User inputs and keyboard shortcuts.

Create a new sequence called Manage_User_Inputs_Example

manage-user-inputs-rpa-uipath

Once the sequence opened in the UiPath Studio, On the Design ribbon tab, you can see a Us

h" />

Now the Uipath has created a sequence with Ctrl c as shown below
sequence-with-user-events-rpa-uipat

Add the Message box activity inside the Event Handler activity and then write a message inside the message box as You are Trying to Copy

add-message-in-the-message-box-rpa-uipath

Save the sequence and run, Once you run the sequence no pop-up will occur on the window, because the UiPath will be waiting for user inputs. As soon as you press Ctrl+c the pop-up message will occur saying that You are Trying to Copy
pup-up-message-box-rpa-uipath