In this video, we will continue with our previous desktop automation.
So far we have learned passing data using variables and using them in our recording
sequence.
There are different methods of receiving data from simple applications like an excel file
or a web browser up to the complex legacy and virtual applications like Citrix.
Today, we'll be using the simplest method through user inputs using keyboard entries.
We'll discuss getting data from different apps and how to integrate them in a separate
video.
In UiPath, we use INPUT data to store in a variable which can be used to pass data from
one activity to another.
In the previous tutorial, we learned how to automate simple calculation through mouse
clicks on the calculator app.
This time we'll ask the user to put the numbers manually.
Let's start by creating 3 variables.
We will use these variables to store the user's input.
Let's name it, "number1", "number 2" and the "Operator".
All will have a variable type string.
Now the variable "Operator" gives us this warning message.
So we cannot use because it's a special keyword used by UiPath.
Let's replace it with "SelectedOperator"
Now, let's give them default values so that we can test each variable later.
Let's say 123 for number1, 456 for number 2 and "+" for the operator.
We are putting it inside a quotation since we're using a variable type "String".
Starting from now, if you haven't noticed, I always create default values for newly created
variables.
This is the simplest way for us to see the results after executing the workflow.
This will check if it's working properly before we use data from another variable or from
another activity.
This is very helpful especially if you are starting to learn UiPath.
Let's go to our Calculator app workflow.
We'll try to replace this 3 click activities so we can use our 3 new created variables.
First, let's delete the number 3 activity.
Let's find "type into" and put it here.
Now, most of the time we need to indicate the text area where we need to type.
But that's not the case with our calculator.
The app allows you to type a number on your keyboard and it will take it.
So let's leave it blank.
The input will be the "number1" which will have a value of "123".
Let me add a delay after every character has been entered in the Options section.
Let's say 500.
This is in milliseconds so that's 1/2 of a second.
Let's copy this activity for our "number2".
Remember, when you copy an activity, all of its properties will be copied as well.
So there will be a delay as well.
Then we can just rename the input as "number2".
Let's delete the "Number 5" activity.
Our workflow is currently running sequentially in one direction since we're only using one
operator.
To provide additional option, we can expand our workflow by setting up a condition.
Let's use "If" activity and drag it after the number 1.
. In the previous tutorial, we mentioned about "Flow Decision".
They have a similar purpose.
But we're inside the "Do" sequence, the "Flow Decision" will not work because it's only
applicable in the Main workflow.
So it's best to use "If" in this situation.
Now we can declare our condition.
Let's put the variable, SelectedOperator = "+" Then we can drag the "Add button" activity
here.
That means, if the value of the variable "SelectedOperator" is equal to "+" then it will click the Add
button.
Otherwise, it will perform a different activity.
Let copy this and put it in our "Else" box and let's change this to a minus sign by clicking
the option menu and selecting Indicate on screen.
This will take a screenshot of the image we want to click on the screen.
Before doing this make sure that you already opened the calculator app.
Let's click the minus sign.
Let's put an appropriate name for it.
Let's run it to see how it works.
Nice.
So our variables are working correctly.
Let's setup another type of INPUT.
This time we'll automate the calculations based on user inputs through an INPUT dialog
box.
Let's add an INPUT dialog box and name it InputBox number 1.
Let's put the title and label for the INPUT box.
Next we will store the user inputs into the variables we previously created.
Now, notice if I try to enter the variable "Number1".
It gives this error message.
Saying that the variable wasn't declared.
If we go to the the Variables panel, it's not here.
There's only one explanation to that.
The variable is not globally declared.
Let's go to the Recording Sequence.
As you can see.
The scope of this variable is limited only inside the "Do" sequence container.
For us to be able to use it outside this sequence, we need to change the scope to "Main".
Let's do the same with other 2 variables.
Now let's go back to our INPUT dialog
The variables are now visible so we use it with the INPUT activity.
Let's copy this INPUT box for our second number and rename it to InputBox number 2.
Let's modify the label.
And the variable will be number2.
I'll copy this one more time for our operator activity.
I will rename it and also change the title and label.
Since we use 2 different operations - plus and minus.
We'll give our user list of options.
So how do we do that?
We've been using a variable type "String"since the first video.
Let me introduce you today to an array.
If you are a programmer, this is very common.
But if you're not think of an array like a row of bookshelves where you can pick any
book you like from.
To provide this option to the user, we set an array with two values as our input for
our operator.
Let's click Options under Input.
We can directly set the array here by typing this:
{"+","-"}.
We enclosed our array in braces.
This will mark the beginning and end of the array.
Then we enclosed each value in quotation since we are using a String type array.
We separate each value using a comma.
Instead of putting the values here directly.
Let me create a variable and stores this array.
So let' copy it.
Let's go to the variable section and let's add a variable called OperatorList.
For the type, we select Array of [T] then select String.
Then we paste the array here.
Then we click the Operator activity and put the variable in the Options.
There, we already have an input for our operators.
Next the output will be operator selected by the user.
So we put the variable "SelectedOperator" here.
Let me make this as a start node so I can show you how it looks like after running it.
There, you have the plus and minus option.
Next, let's organize these 3 input dialogs into one container.
Let's create a "Sequence".
Then we can put the 3 boxes inside.
Here's a trick to do it all at once, Press and hold CTRL key and click these 3 boxes.
Then Press CTRL+x to cut it.
Let's open the sequence and press Crtl+V to paste them.
Let's arrange the sequence.
Let's go back to the main workflow so we can arrange it and give a proper name to our sequence.
Let's name it "User Input" and "Calculator" for this one.
Good.
everything is clear.
There's one last thing I wanted to do.
Let's open the variables panel.
Some of these variables are not in used which are automatically generated by UiPath.
Since we have created and used our own variables, we can clear the unreferenced variable by
going to the Design menu, Manage Variables> and select Remove Unreferenced.
So there it removes the ones that are not in use.
OK we are ready.
Let's run our workflow.
Let's put the first number.
Let's select plus, and let's put in the 2nd number.
Perfect!
It performs the "plus" operation.
It also displays the result in the message box and closes the application.
Let's run it again.
This time let's use minus.
Awesome!
Today, you have learn how to design an automation that will automatically select an operation
based on the user inputs.
Isn't it great?
In the next video, let's learn how to use an existing workflow with another one.
Stay tuned.