10.2.3) Switch

It is a type of control flow statement that executes a set of statements out of multiple, based on the value of a specific expression. In other words, we use it instead of an If statement when we need at least 3 potential courses of action. This is done through the condition, which is not Boolean like in the case of If statement, but multiple.


What are some business scenarios in which I will use Switch?

  • An invoice that has 3 potential statuses (not started, pending, approved) and 3 sets of actions for each one
  • A process of automatically ordering raw materials to 4 suppliers based on certain conditions

We use Switch in 2 ways
1) Sequence
2) Flow chart

Difference between Switch and Flow Switch?
  • We can use normal Switch is sequence based mechanism. We can drag it into Flow chart. But flow switch cannot be used in sequence. 
  • Using Flow Switch we can add only 12 cases whereas in Switch we can add unlimited cases

Example:
Step 1: Create Sequence
Step 2: 
  • Add Input Dialog. And enter the Label and Title
  • In the properties panel,  put "Result"/output by creating a new variable "FruitName" which is string
Step 3: 
  • Add Switch.
  • Create Case: Apple. Note: Do not add quotes for string 
  • Create one more case Cherry
  • In default add an message box "Did not match any value"
  • Inside Apple activity add Message box "You have entered "+ FruitName.to String
  • Inside Cherry activity add Message box "You have entered "+ FruitName.to String
        

Using switch inside Flowchart

Input Dialog box will be


And Switch will be like

                


No comments:

Post a Comment

Sequence and Flowcharts

  UiPath recommends that the first part of the Robot should start with Flowchart or Sequence. We can nest Sequence inside Sequence, Flowchar...