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
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.
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
Once the sequence has been created successfully, include Assign activity inside it and then create a variable.
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
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.
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.
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
Now, save the sequence and run. Once the sequence executes, the message will be displayed as shown below.
Now let us change the variable value to
10 and save then execute
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
Add Assign activity inside the sequence and create a variable called
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.
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
Next, add case as
A and add Write Line activity inside the case and enter the text inside the WriteLine as
Next, add a new case as
B and add the Write Line activity inside case B and add the text as
Add another case
C and Write Line activity inside it and then add text as
Now, save the sequence and run, once the sequence starts to execute the output will be Please Improve.
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
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.
The following example demonstrates whether the given number is even or odd.
Drag and drop the Input dialog into the If condition sequence.
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.
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.
The output will be shown as below
The Following example demonstrates Managing User inputs and keyboard shortcuts.
Create a new sequence called Manage_User_Inputs_Example
Once the sequence opened in the UiPath Studio, On the Design ribbon tab, you can see a Us
Now the Uipath has created a sequence with Ctrl c as shown below
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
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