You are on page 1of 123

Variables and Arguments

Day 01 – Module 02
Richard Win Putra & Ali Gunawan
RPA UiPath Prep Class
Batch 2
Creating Solutions through Education with Creativity and Technology 1
OUTLINES
Variables

Invoke Workflow and Arguments


Data Types
Control Flow
Practice
2
LEARNING OBJECTIVES
• Variables and arguments, or how data is
collected, stored, processed, and passed
between various activities and workflows.
• Control flow, or how the activities are
executed throughout the process.
3
What are variables?
• Variables are containers that can hold multiple
data entries (values) of the same data type.

• For example, EmailAddress can be a variable that


holds the value "rpadeveloper@uipath.com".

• The value of a variable can change through


external input, data manipulation or passing from
one activity to another.
4
Why are they important?
Variables help us pass data from one activity to
another. Advancing with any automation
process would be hardly possible without using
variables.

5
Variables are configured through their
properties. You can set them in the Variables
panel. The main properties in UiPath are:
• Name
• Type
• Default Value
• Scope
6
Name
• It should be as descriptive as possible to make
your automation easy to read by other
developers and to save time. While not the
only option, we recommend using PascalCase
for variable names.
• The variable's name is its unique ID and it
defines the way it is displayed and used.
7
Type
It defines what kind of data can be stored in the
variable. In UiPath, the type is declared when
the variable is created, however there are some
types that can accommodate different types of
data.

8
Value
In general, variables have initial values that
change throughout the process. For most
variables, if no initial value is assigned when the
variable is declared, there is a default rule that
assigns a value.

9
Scope
• The part of the workflow in which the variable can be used. Some
variables can be global (used throughout the workflow), others
local (used inside an activity).
• In real automation scenarios, there are many variables in use.
Making all of them unnecessarily global can cause efficiency issues
as well as create the conditions for confusion.
• In UiPath, the scope of a variable cannot exceed the workflow in
which it was defined. Since business automation projects rarely
consist of single workflows, we need a different kind of vehicle to
pass data between workflows, and this is called an argument.
• You will learn more about arguments shortly in the course.

10
Watch Video

11
Creating Variables
There are three main ways to create variables in
UiPath:
• From the Variables panel
• From Expressions
• From the Properties panel

12
• From the Activities panel, drag an activity
to the Designer panel. Right-click a field and
select Create Variable from the context
menu, or press Ctrl+K. The Set Var field is
displayed.
• Fill in the name and press Enter. The variable
is created and visible in the field. Check its
scope and type in the Variables panel.

13
From Expressions
• Variables can be created from expressions
directly in an activity input field or the
Expression Editor. Select a part of the
expression and press Ctrl+K.
• The Set Var field is displayed. Fill in the name
and press Enter. Check its type and scope in
the Variables panel.
14
From Expressions
• Select a part of the expression and press Ctrl+K.
The Set Var field is displayed.
• Fill in the name and press Enter. The variable is created.
Check its scope and type in the Variables panel.

15
From the Properties panel
• In the Properties panel of any activity, select a
field that can be edited press Ctrl+K. The Set
Var field is displayed. Fill in the name and
press Enter.
• Check its type and scope in the Variables
panel.

16
From the Properties Panel
• In the Properties panel
of any activity, right-click
a field that can be edited,
and select Create
Variable from the
context menu, or press
Ctrl+K. The Set Var field
is displayed.
• Fill in the name and press
Enter. The variable is
created and visible in the
field. Check its scope and
type in
the Variables panel.

17
From the Variables panel
Navigate to the Variables panel, select the
‘Create Variable’ line and type in the name.
Whenever needed, provide its name in the
Designer panel or in the desired Properties field.

18
From the Variables Panel

• In the Designer panel, click Variables. The Variables panel is


displayed.
• Click the Create Variable line, and fill in the name. A new variable
is created.

19
Removing Variables
• In the Variables panel, right-click a variable and select
the Delete option.
• In the Variables panel, select a variable and press the Delete key.

20
Remove Unused Variables.

• You can also remove all the variables that


are defined in the Variables panel, but
not used in your currently opened project.
• To do so, on the Design ribbon tab
click Remove Unused Variables. This
also removes variables that are unused
but mentioned in annotations.
21
The Variables Panel

22
The Context Menu for Variables

23
24
Types of Variables
• Text Variables
• Text or False Variables
• Number Variables
• Array Variables
• Date and Time Variables
• Data Table Variable

25
Text Variables
System.String: Used to store text. This type of
data comes with many specific methods of
processing, and will be addressed in depth in
another lesson, namely Data Manipulation.

26
Text Variables

1.Create a sequence.
2.Create two simple string variables, FullName and FirstLetter.

27
Text Variables

28
29
Boolean : True or False Variable

System.Boolean: Used to store one of two


values – True or False.

30
True or False Variable

31
32
33
True or False Variable

34
Number Variables
• Used to store numbers. There are different sub-
types of numerical variables. For a few examples:
• Int32 - System.Int32 (signed integers): 10, 299, -
100, 0x69
• Long - System.Int64 (long integers):
5435435343O, -11332424D
• Double - System.Double (allows decimals, 15-16
digits precision): 19.1234567891011
35
Number Variables

36
37
Number Variables

38
Collection (category)
This category reunites all the collections of objects. Collections are largely
used for handling and processing complex data. Some of the most
encountered collections are:
• Array - ArrayOf<T> or System.DataType[]: used to store multiple values of
the same data type. The size (number of objects) is defined at creation.
• List - System.Collections.Generic.List<T>: used to store multiple values of
the same data type, just like Arrays. Unlike Arrays, their size is dynamic.
• Dictionary - System.Collections.Generic.Dictionary<TKey, TValue>: used to
store objects in the form of (key, value) pairs, where each of the two can
be of a separate data type.

We will cover Arrays later in this lesson, and Lists and Dictionaries in more
detail in the Data Manipulation lesson.

39
Array Variables
• The array is a data type that enables storing
multiple values of the same variable or
argument. Think of it as a group of elements
with a size that is defined at creation, and
where each item can be identified by its index.
• In UiPath Studio, you can create arrays of
numbers, of strings, of Boolean values and so
on.
40
What are some business scenarios in which I will
use arrays?

• When we want to save the names of the months


to a variable.
• When a fixed collection of bank accounts has to
be stored and used in the payment process.
• When all the invoices paid in the previous month
have to be processed.
• When the names of the employees in a certain
unit have to be verified in a database.
41
Video demo - Arrays

42
Array Variables

43
44
45
46
Array Variables

47
Date and Time Variables
• DateTime - System.DateTime: Used to store specific time coordinates
(mm/dd/yyyy hh:mm:ss).
This kind of variable provides a series of specific processing methods
(subtracting days, calculating time remaining vs. today, and so on).
For example, to get the current time, assign the expression DateTime.Now
to a variable of type DateTime.
• TimeSpan - System.TimeSpan: Used to store information about a duration
(dd:hh:mm:ss). You can use it to measure the duration between two
variables of the type DateTime.
For example, you can save the time at the start of the process in one
variable (of type DateTime), the time at the end in another (of type
DateTime) and store the difference in a variable of type TimeSpan.

48
Date and Time Variables

49
50
51
52
Data Table Variables
• DataTable variables represent a type of
variable that can store big pieces of
information, and act as a database or a simple
spreadsheet with rows and columns.
• We will cover DataTables in the Excel and
DataTables lesson.

53
Data Table Variables

54
55
56
57
Generic Value Variable
This is a UiPath proprietary variable type that
can store any kind of data, including text,
numbers, dates, and arrays. This type is mainly
used in activities in which we are not sure what
type of data we will receive, yet in general the
use of this is temporary.

58
Generic Value Variable

59
Generic Value Variable

60
Generic Value Variable

61
Generic Value Variable

62
Generic Value Variable

63
Generic Value Variable

64
Workflows
• A workflow represents a small piece of automation
that you can take and re-use in your projects. It is
basically your canvas, the place where you design and
work with all the UiPath Studio activities and it defines
the flow of your automation. Hence the name,
workflow.

• UiPath Studio provides you with predefined workflow


layouts to suit all the needs of a fast and reliable
automation process.

65
The workflow layouts are:
• Sequences
• Flowcharts
• State Machines

66
Sequences
• Sequences are the smallest type of project. They are suitable to linear
processes as they enable you to go from one activity to another
seamlessly, and act as a single block activity.
• One of the key features of sequences is that they can be reused time and
again, as a standalone automation or as part of a state machine or
flowchart.
• For example, you can create a sequence to take information from
a .pdf file and add it to a spreadsheet, and reuse it in a different setting,
while changing just a few properties.
• Please take into consideration that whenever you wish to copy a large
number of activities from one sequence to another, it is recommended to
scroll down to the bottom of the Designer panel beforehand. This is due to
a Windows Workflow Foundation limitation.

67
Sequences

68
Sequences

69
70
Sequences

71
Flowchart
• Flowcharts can be used in a variety of settings, from
large jobs to small projects that you can reuse in other
projects.
• The most important aspect of flowcharts is that, unlike
sequences, they present multiple branching logical
operators, that enable you to create complex business
processes and connect activities in multiple ways.
• Flowcharts come with the Auto Arrange option in the
context menu.

72
Flowchart

73
74
75
State Machines
• A state machine is a type of automation that uses a finite
number of states in its execution. It can go into a state
when it is triggered by an activity, and it exits that state
when another activity is triggered.
• Another important aspect of state machines are transitions,
as they also enable you to add conditions based on which
to jump from one state to another. These are represented
by arrows or branches between states.
• There are two activities that are specific to state machines,
namely State and Final State, found under Workflow > State
Machine.

76
State Machines

• The State activity contains three sections, Entry, Exit and


Transition(s), while the Final State only contains one
section, Entry. Both of these activities can be expanded by
double-clicking them, to view more information and edit
them.

• The Entry and Exit sections enable you to add entry and
exit triggers for the selected state, while the Transition(s)
section displays all the transitions linked to the selected
state.
77
78
State Machine : Example

79
State Machine : Example

80
State Machine : Example

81
State Machine : Example

82
State Machine : Example

83
Arguments
Arguments are very similar to variables:
• They store data dynamically
• They have the same data types
• They support the same methods and properties
The difference is that they pass data between workflows,
and they have an additional property for this – the
direction. Arguments have specific directions: In, Out, and
In/Out. These tell the Robot where the information
stored in them is supposed to go.
84
Video demo - Invoke
workflow and arguments

85
Creating arguments
Argument names should be in PascalCase with a prefix
stating the argument direction, such as
in_DefaultTimeout, in_FileName, out_TextResult,
io_RetryNumber.
• From expressions
• From the Properties panel
• From the Arguments Ppanel

86
From expressions
• Directly in an activity input field or the Expression
Editor. Select a part of the expression and press
Ctrl+M (for In arguments) or Ctrl+Shift+M (for
Out arguments). The Set Arg field is displayed.
• Fill in the name and press Enter. The argument is
created. Check its direction and type in the
Arguments panel. Arguments created in these
ways automatically receive the type according to
the activity.

87
From the Properties panel
• In the Properties panel of any activity, right-click a field
that can be edited, and select Create In Argument or
Create Out Argument from the context menu.
Alternatively, press Ctrl+M (In) or Ctrl+Shift+M (Out).
The Set Arg field is displayed.
• Fill in the name and press Enter. The argument is
created and visible in the field. Check its direction and
type in the Arguments panel. The argument type is
automatically generated depending on the selected
property.

88
From the Arguments Ppanel
Navigate to the Arguments panel. Select the
Create Argument line, and fill in the name,
direction and type. A new argument is created.

89
What is control flow?
• It is the order in which activities are executed
or evaluated in a software project.
• There are two concepts through which the
control flow is enacted:

90
The workflow layouts
• There are 4 predefined workflow layouts –
Sequence, Flowchart, State Machine and Global
Exception Handler.
• We will cover them in depth in the “Project
Organization in Studio” course. For now, let’s
focus on the difference between sequences and
flowcharts, as we will use both extensively in our
examples throughout the entire course.

91
The workflow layouts
1. In sequences, the process steps flow in a clear succession. Decision
trees are rarely used.
Activities in sequences are easier to read and maintain, thus they
are highly recommended for simple, linear workflows.
2. In flowcharts, the individual activities are a bit more difficult to
read and edit, but the flows between them are much clearer.
Use flowcharts when decision points and branching are needed in
order to accommodate complex scenarios and decision
mechanisms.

92
The control flow statements
The activities and methods used to define the
decisions to be made during the execution of a
workflow.

The most common control flow statements


are If, While, Do While, For Each, Switch,
and Parallel. We will focus on them one by one.

93
The If Statement
In UiPath, the If statement is comprised from the
elements you would expect it to be:
• The Condition that is verified (with 2 potential
outcomes – true or false).
• The Then branch - the set of actions to be
executed when the condition is true.
• The Else branch - the set of actions to be
executed when the condition is false.
94
The If Statement
What is different is that, based on the chosen
type of layout, there are 2 corresponding
activities that fulfill the If statement role:
• The If activity in sequences.
• The Flow Decision activity in flowcharts.

95
What are some business scenarios in
which I will use the If statement?
Whenever there are two courses of action that are not
arbitrary, an If statement will most likely be used:
• Checking the status of a payment (done/not done) and
performing a set of operations in each case.
• Making sure that the outcome of the previous operation in
the sequence is successful.
• Checking the balance of an account to ensure that there is
enough money to pay an invoice.
• Checking if something has happened in a system like, if an
element or an image exists and performing an action based
on that.
96
Video demo - If statements

97
Loops
Loops are repetitions of a set of operations
based on a given condition. In UiPath, the most
important loops are: Do While, While and For
Each.
• Do While
• While
• For Each

98
Do While
• It executes a specific sequence while a condition is
met. The condition is evaluated after each execution of
the statements.
• For example, a robot could perform a refresh
command on a website and then check if a relevant
element was loaded. It will continue the refresh - check
cycle until the element is loaded.
• The key difference between Do While and While is that
for Do While, the activities contained within it are
executed at least once.

99
While
It executes a specific sequence while a condition
is met. The condition is evaluated before each
execution of the statements.

For example, if a Robot would play Blackjack, it


should calculate the hand before deciding
whether to draw another card.

100
For Each
• It performs an activity or a series of activities
on each element of an input collection.
• This is very useful in data processing. Consider
an Array of integers. For Each would enable
the robot to check whether each numeric item
fulfills a certain condition.

101
How do I exit a loop?
Loops are fun, but we should know how to stop the
ride at some point. There are multiple ways to exit
a loop:
• The While and Do While loops will exit when upon
checking, the condition is no longer true.
• The For Each loop will exit when it has finished
processing every item in the input collection.
• The Break activity enables you to exit the current
loop activity (e.g. For Each, While, or Do While)
at a chosen point and continues the workflow
with the activity that follows it.

102
Video demo - Do While

103
Video demo - For Each

104
Switch
• It is a type of control flow statement that executes a
set of activities 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.

105
Switch
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.

106
Video demo - Switch

107
Parallel
• The Parallel activity enables you to execute two
or more child activity branches at the same time.
• In UiPath Studio, the Parallel activity can be found
in the Activities panel,
under Workflow > Control > Parallel.
• The Parallel activity finishes only after all child
activities are complete or when its
CompletionCondition property evaluates to true.

108
Parallel
Why is it important?
• The Parallel activity is very beneficial when
there are one or more blocking activities in
the branches, because it executes all child
activities simultaneously and asynchronously,
thus saving time and being very efficient.

109
Where do I use it?
• Let's imagine a Sequence workflow that contains two other Sequence
activities.
• The first sequence must download a .pdf file on a webpage and uses
a 'Wait for Download' activity that waits for the download to
complete before any further processing of the file in the automation.
• The second sequence gets data from an invoice and sends the output
by email to a specific recipient.
• What the Parallel activity does is that it won't stop the automation to
wait for the blocking activity to finish downloading, instead it will
switch between the child activity branches until they all finish
executing or when its Completion Condition property evaluates to
true

110
111
Practice Time

112
Practice 1 - For Each and If Statement
• Find the smallest and biggest numbers in an
array
• Use For Each, Assign and If Statements
to find the minimum and maximum
number in an array of Int32 elements
and print it.
• Note: You can initialize the Array with {7,
5, 2, 4, 3, 9} or with your own values, as
long as they are integers.

113
Practice 1 solution

114
Practice 2 - GenericValue
Adding and Concatenating GenericValue Variables
Create four variables of the GenericValue type in your sequence:
• A with value “123”
• B with value “456”
• C with value 123
• D with value 456
Print to the console various operations with them and see what
is the result:
• A+B
• C+D
• A+C
• C+A

115
Practice 2 solution
• As presented, GenericValue variables can store various
types of data.
• The "+" operator is interpreted as Concatenation in
case of Strings and Addition in case of Int32. When "+"
is used between GenericValue variables, it is
interpreted based on the value of the first variable:
• If its value is "123", it is considered a String, therefore
the operation is Concatenation
• If its value is 123, it is considered Int32, therefore the
operation is Addition.

116
Practice 3 - Switch
• Separate a collection of error codes using Switch
• Considering a collection of error codes stored
in an Array of Strings, separate them based
on their type of error code ("Ax", "Bx" or
“Cx”) and store them in 3 different arrays.
• Note: The initial Array should contain the
following values:
• "Ax001","Ax002","Ax003","Ax004","Ax00
5","Bx001","Bx002","Bx003","Cx001","Cx
002","Cx003","Cx004"

117
Practice 3 solution
1. Create the first Array of strings variable with default value of
{"Ax001","Ax002","Ax003","Ax004","Ax005","Bx001","Bx002","Bx003","Cx
001","Cx002","Cx003","Cx004"}
2. Create 3 Array of strings variables and instantiate them in the default by
using new string(){}
3. Use a 'For Each' loop to iterate through the initial array and:
1. Use a 'Switch' inside the loop with the expression built to extract the first 2
letters using the 'Substring' method: item.Substring(0,2).ToLower.
2. For each of the 3 cases ("ax", "bx", "cx"), use the 'Concat' method to add the
item to the corresponding Array: i.e. AxArray.Concat({item}).ToArray.
4. Use 3 'Log Message' activities to print the content of each of the 3 Arrays,
by using the 'String.Join' method: i.e. string.Join(" ",BxArray).

118
Practice 4 - Invoke Workflow File
• Create a simple interest calculator using a separate workflow and
arguments
• Create a simple interest calculator. In your ‘Main’ workflow, ask the user to
enter the amount of the initial deposit and the period (multiple choice,
e.g. 1 year, 3 years, 5 years). Store the input in two variables. Afterwards,
create a third variable that will store the value of the final earning.
• Create a new workflow and use it to calculate a simple interest using the
user input and take into consideration the value of the rate/year. Afterwards,
display on screen the cumulated interest at the end of the period and the
final deposit balance.
• Note: The formula to calculate the interest can be 'Principal amount x Rate
per year x Period chosen / 100'. Use a ‘Switch’ activity to calculate the
interest for all the period options (e.g: 1 year, 3 years, 5 years) and assign
the result to an argument.

119
Practice 4 solution

120
121
122
TERIMA KASIH

123

You might also like