studio
latest
false
UiPath logo, featuring letters U and I in white

Studio User Guide

Last updated Dec 17, 2024

Example of Using an If Activity

To exemplify how you can use the If activity, let’s create an automation that asks the user for two numbers, checks to see if one is divisible by the other, and depending on the result, displays a different message in the Output panel.

  1. Create a new sequence.
  2. Create two integer variables, FirstNumber and SecondNumber for example.
  3. Add two Input Dialog activities to the Designer panel.
  4. Type titles and labels for both activities and, in the Value entered fields, add the FirstNumber and SecondNumber variables.
  5. Add an If activity to the Designer panel, under the previously added Input Dialog ones.
  6. In the Condition section, type FirstNumber mod SecondNumber = 0. This expression checks if the first number is divisible to the second one, using the mod operator.
  7. In the Then section, add a Write Line activity.
  8. On the right side of the Text field, select Plus docs image > Open in Advanced Editor.
  9. Inside the Expression Editor window, type FirstNumber.ToString + " is divisible by "+ SecondNumber.ToString + ".". This is the message that is displayed if the first number is divisible by the second one.
  10. Click Show Else to display the Else section, and then add another Write Line activity in the Else section.
  11. Inside the Expression Editor window, type FirstNumber.ToString + " is NOT divisible by "+ SecondNumber.ToString + ".". This is the message that is displayed if the first number is not divisible with the second one.


  12. Press F5. The automation is executed.
  13. Add numbers when prompted. Note that the Output panel displays the result, depending on the values added in the Input Dialog windows.




Was this page helpful?

Get The Help You Need
Learning RPA - Automation Courses
UiPath Community Forum
Uipath Logo White
Trust and Security
© 2005-2024 UiPath. All rights reserved.