Lesson 3 Variables and Arguments
Lesson 3 Variables and Arguments
and Development
V3.0
1|Page
Slide 2
Lesson 3
Variables and Arguments
2|Page
Slide 3
Agenda
02 Variables Panel
07 Arguments vs. Variables
03 Scope of a Variable
04 Arguments
05 Arguments Panel
3|Page
Slide 4
Learning Objectives
Explain arguments
4|Page
Slide 5
5|Page
Slide 6
Introduction to Variables
Variables are containers that are used to store multiple types of data. A variable:
• makes it easier to label and store data which can later be used
throughout the automation process
Variables are containers that are used to store multiple types of data. Using
variables makes it easier to label and store data which can later be used throughout
the automation process.
A variable has an initial value that may change during the program. The value of a
variable can change through an external input, data manipulation, or passing from
one activity to another. A collection variable contains multiple data entries (of the
same type).
6|Page
Slide 7
Properties of Variables
01 02
Name Type
Name of the variable Kind of data that the
variable is intended to
store
03 04
Value Scope
Data that a variable Designates parts of a
holds (may change program that can use a
during the process) variable (local, global)
The user can configure a variable through its properties. The variables have the
following properties:
• Name: The name of a variable is its unique ID. It represents the "title" of the
information that is being stored by the variable. A variable should be named to
represent all possible values that it might contain. The name is essential in
programming, because the user "accesses" the variable through the name. Every
variable must have a unique name and it should be descriptive enough so that
other users can easily read it and save time.
• Type: Type defines the kind of data that the variable is intended to store. The
type is declared when the variable is created. There are some specific types that
are more generic and can accommodate different types of data. The most
common (universal) types of a variable are: text, number, array, date/time,
Boolean, and data tables.
• Value: Value is the data that a variable holds. The value of a variable may
change during the process. Suppose a variable named ‘tasks’ is assigned a
value ’12’ initially. At another point, ‘tasks’ may be assigned the value ’27’. If no
initial value is assigned at the creation of the variable, a default rule assigns a
value to the variable.
• Scope: Scope defines from where the variable can be accessed in the workflow.
The variables can be global or local. If the user defines a variable with local
scope, then outside processes cannot access it. There are always several
variables in use, so the users should avoid making multiple variables
unnecessarily global and not a part of the program, as it may cause efficiency
issues.
7|Page
Slide 8
A variable’s name should be meaningful and hint towards the information it stores. While naming any
variable, the user should:
Assign names in a consistent manner Keep the variable names descriptive yet
short
The name of a variable should be meaningful and describe the information it stores.
This makes it easier to understand the purpose of the variable and to maintain it.
For this, the users must follow the best practices for naming a variable and should:
• Use clear & meaningful names (the name of the variable should accurately
describe its content)
• Assign names in a consistent manner
• Adhere to using upper Camel Case, e.g. FirstName, LastName
• Keep variable names descriptive yet short
8|Page
Slide 9
Types of Variables
String DataTable
01 05
02
Boolean QueueItem
02 06
Number Array
03 07
The type of a variable defines the type of data that can be stored inside the variable.
The different types of variables available in UiPath Studio are:
These are discussed in detail in the subsequent slides. In addition to these, for
complex situations, the users can declare data types of .Net type variables which
are also available in UiPath Studio.
Also, in addition to these, there are two collection variables: Lists and Dictionaries
which will be discussed in Lesson 6 of this course.
9|Page
Slide 10
1. String Variables
String (Text) Variables are variables in which the users can store only strings, i.e., a
sequence of text. These variables can store information like usernames, employee
names, etc. When assigning values to a string variable, the values are typed in
double quotes.
String variables are used to store text and reuse it in the code for specific actions. It
can be the name of a person, the address of a person, etc.
Example:
Consider that an invoice is being generated. There are various fields mentioned in
the invoice. These fields are represented using different variables. Here, the name of
the company is an example of a string variable as it takes a string value. (Company
Name could be XYZ Corp.)
• Variable name can be CompName with value “XYZ Corp”.
10 | P a g e
Slide 11
2. Boolean Variables
A Boolean variable (also known as true-false variable) has only two possible values:
“True” or “False”.
The Boolean variable is primarily associated with conditional statements, which allow
different actions by changing control flow depending on whether a programmer-
specified Boolean condition evaluates to true or false. Thus, Boolean variable is
commonly used with control statements to determine the flow of a program as they
enable the user to make decisions. A variable holds TRUE when a condition is met,
FALSE when a condition is not met.
Example:
Holds TRUE when the item in the invoice is available, holds FALSE when the item is
unavailable.
11 | P a g e
Slide 12
3. Number Variables
Number variables (also known as integer) are the variables in which the user can
store numeric values. They are used to execute equations or perform comparisons,
pass important data, etc. Number variables specify values such as age of a person:
(eg: 34). Number variables are also known as Integer or Int32.
Example:
Item Quantity.
• Variable name can be ItemQuant with value 50.
12 | P a g e
Slide 13
The date and time variable is a type of variable that enables you to store information
about any date and time such as a variable Today holds today’s date.
The main usage of the Date & Time variable is to store a specific date and time
inside or to perform other operations with them. (Ex. Calculate how many days are
left until the end of the month). They may be used to append dates to time-sensitive
invoices or documents.
Example:
Invoice Date
• Variable name can be InvDate with value 01/01/2020.
13 | P a g e
Slide 14
5. DataTable Variables
DataTable variables can store tabular data in rows and columns and may hold a
large amount of information and act as a database. In UiPath Studio, DataTable
variables can be found in the Browse and Select a .Net Type window. You can
access this window by clicking the Browser for Types option from the drop-down
menu in the Variable Type column of the Variables panel.
The practical usage of data tables is to store big pieces of information and do certain
operations on them, such as filtering, searching, copying, etc. They are often used to
migrate data from a database to another, extract information from a website and
store it locally in a spreadsheet.
Example:
List of all items in the invoice with the quantity of each
• Variable name can be dt_InvItem with values Item1, Item2, Item3,….
14 | P a g e
Slide 15
6. QueueItem Variables
The QueueItem variable stores an item that has been extracted from a container of
items, a queue. Through this extraction, the user can further use the queue items in
other processes. It is a proprietary variable of UiPath.
Let’s call the employee’s machine as the First machine and the machine where the
third-party application is installed as the Second machine.
The employee creates two automation projects. The first automation project is
created on the First machine to upload the client data to Orchestrator. The second
automation project is created on the Second machine to retrieve the client data from
Orchestrator for processing.
15 | P a g e
QueueItem variable is created called TransItem. Upon execution, the
automation project retrieves each transaction item from CustomerQueue and
stores it in TransItem. And then the stored value of TransItem is further
processed in the third-party application.
16 | P a g e
Slide 16
7. Array Variables
An array is a data structure that contains a group of elements of the same data type,
such as an integer or string. So, an Array variable enables users to store multiple
values of the same data type.
An array is a type of collection variable used to store multiple entries. The size of an
array is defined when it is created, and it is not dynamic.
A search engine may use an array to store Web pages found in a search performed
by the user.
When displaying the results, the program will output one element of the array at a
time. This may be done for a specified number of values or until all the values stored
in the array have been displayed.
While the program could create a new variable for each result found, storing the
results in an array is a more efficient way to manage memory.
Example:
• Variable name can be ArrCompName which is an array of two strings: Company
Name 1 and Company Name 2
(Based on previous examples of String Variables, the value of this array could be
{“ABC”, “XYZ”}).
17 | P a g e
Slide 17
Array String
Array:
• It is a fixed-size sequenced collection of elements of the same base types that
share a single name and can be used to represent a list of names or numbers.
• Its elements are stored contiguously in increasing memory locations.
• It is a special variable that can hold more than one value at a time.
• Its length is predefined.
String:
• It is a sequence of single characters represented as a single data type.
• It can be stored in any manner in memory locations.
• It can hold only character data.
• Its size is not predefined.
18 | P a g e
Slide 18
Variables Panel
• Introduction to Variables Panel
• Managing variables
This section gives an overview of the Variables panel and how to manage variables.
19 | P a g e
Slide 19
Studio has a Variables Panel that enables the users to create variables and modify
them.
The panel is located at the bottom right side of the Activities panel and it is hidden by
default. When clicked, the panel opens and displays the existing variables in the
project and allows the user to modify them. Whenever a user changes the name of a
variable in this panel, it automatically gets updated at all occurrences in the current
file.
The Variables Panel consists of fields through which the users can define the
different properties of a variable. For both existing and new variables, it has the
following fields:
• Name: The user defines a variable by giving it a name. It is the title of the data. If
the user renames a variable in the Variables Panel, it will be renamed in all
instances where it is used. This is useful in complex workflows. If the user does
not add a name to a variable, it is automatically generated.
• Variable Type: The user specifies the data type that the variable will store. The
data type for the variables is chosen from the drop-down list. It can be String,
Array, number (integer), etc. Also, the user can change the variable type by
clicking ‘Browse for Types’ and then choosing from the available list.
• Scope: The user specifies the region in which a variable is visible. When the user
defines any variable scope in the container, then it is available only in those
containers where you define it. When the user defines a variable scope in the
main class, then it is available in all containers.
20 | P a g e
• Default: The user specifies the initial value of the variable in the ‘Default’ field. If
this field is empty, the variable is initialized with the default value of its type. For
example, for an Int32, the default value is 0.
The Variables panel also allows the users to copy variables from one workflow to
another and add/edit comments to a variable.
21 | P a g e
Slide 20
Managing Variables
In Studio, a user can create variables from the Variables Panel by clicking ‘Create Variable’.
Step 04
Specify a default
value, if required
In order to manage the variables in UiPath Studio, the users need to perform several
actions on them. These are:
• Creating variables
• Initializing variables
• Removing variables
• Creating Variables:
There are 3 ways to create variables in UiPath:
• From the Variables panel – Open the Variables panel, select ‘Create
Variable’, and fill in the fields as needed. (The variable is created, and its
default type is String.)
• From the Designer panel – Drag an activity from the Activities panel into
the Designer panel (Drag an activity with a variable field visible (i.e.
‘Assign’)) and press Ctrl+K. Name it and then check its properties in the
Variables panel. (The variable is created, and its type is according to the
activity.)
• From the Properties panel – In the Properties panel of the activity, place
the cursor in the field in which the variable is needed (i.e. Output) and
press Ctrl+K. Name it and then check its properties in the Variables panel.
(The variable is created, and its type is according to the selected property.)
The user can create a variable only when the Designer panel contains at least one
activity.
2. Initializing variables
22 | P a g e
While creating a variable, its properties need to be initialized. This is known as the
initialization of a variable. The user can create a variable by following the steps
mentioned earlier and initialize it as follows:
1. Define a name for the variable (one that defines the variable and will be
easy to remember later in the automation workflow)
2. Choose the type of variable from the drop-down list. This list displays the
types that a user has mostly used. In case a different type is needed, the user
can click on “Browse for types…” (The last option in the drop-down list) which
opens a separate screen of the project window, Browse and Select a .Net
Type, where the user can use keywords to search for the desired type. Click
on it to add the type.
3. Choose the scope (available only in the sub-process or for the entire
workflow)
4. Now enter a default value, if required
When a string variable is assigned a value that contains quotations, users need to
use each quotation character twice; otherwise, it will be considered as a string
delimiter.
3. Removing variables
A user can follow either of the following steps to remove a variable:
• Open the Variables panel, right-click a variable, and select
the Delete option.
• Open the Variables panel, select a variable and press the Delete key.
To remove all the unused variables available in the Variables panel, click Remove
Unused Variables on the Design ribbon tab. This removes the variables not used in
the currently opened project and also the ones that are unused but mentioned in
annotations.
23 | P a g e
Slide 21
Classroom Exercise
• In the Designer panel, click the Variables tab. The variables panel is empty.
• Drag and drop Sequence activity in the designer panel.
• In the Variables panel, click Create variable and enter a variable name, say
Username.
• Right click on this variable and select Delete to delete this variable.
• Drag and drop two Message Box activities within the Sequence activity.
• Right click in the text area of the first Message Box activity and select Create
Variable from the context menu.
• Enter variable name, say intMarks, after Set Var.
• In the Variables panel, change its Variable type to Int32 for integer and enter 60 as
its default value.
24 | P a g e
• Run the program to get the output of the integer and the string variable.
25 | P a g e
Slide 22
Scope of a Variable
• Introduction to the Scope of a Variable
26 | P a g e
Slide 23
Scope field determines the containers in which the variable is available. When the
variable is created, the user chooses the scope from the Scope drop-down field
where all major sequences & sections of the program are listed. The user chooses
one of these sequences and the variable will then be available in that part of the
workflow. The scope of the variable is limited to the selected container.
If a variable is declared for a parent activity, then the variable is available in the
entire workflow. However, if the variable is declared in any specific activity, then it is
available only for the scope of that activity. The scope of a variable cannot exceed
the workflow in which it was defined.
27 | P a g e
Slide 24
Scope field determines the containers in which the variable is available. When the
variable is created, user chooses the scope from the Scope drop-down field where
all major sequences & sections of the program are listed. The user chooses one of
these sequences and the variable will then be available in that part of the workflow.
The scope of the variable is limited to the selected container.
If a variable is declared for a parent activity, then the variable is available in the
entire workflow. However, if the variable is declared in any specific activity, then it is
available only for the scope of that activity. The scope of a variable cannot exceed
the workflow in which it is defined.
28 | P a g e
Slide 25
Arguments
• Introduction to Arguments
• Properties of Arguments
• Arguments Panel
29 | P a g e
Slide 26
Introduction to Arguments
Arguments
Store data dynamically
Arguments are used to pass data from one workflow to another by storing the data
dynamically.
They are similar to variables as they store data and pass it on. However, the
variables pass data between activities, while arguments pass data between
workflows. So, arguments enable the users to reuse automation workflows. Hence,
they can be accessed outside the workflows in which they are defined and are useful
in automation projects consisting of multiple workflows.
30 | P a g e
Slide 27
Properties of Arguments
01 02
Name Direction
Name of the Direction from/to
argument which the data is
passed
03 04
Type Value
Kind of data that the Data that an
argument is intended argument holds
to store
The user can configure an argument through its properties, which are similar to that
of variables (except for one, i.e., argument direction). The arguments have the
following properties:
• Name: This specifies the name of the argument. It represents the "title" of the
information that is being stored by the argument. If the user does not add a name
to an argument, it is automatically generated.
• Argument Type: Type defines the kind of data that the argument is intended to
store. In UiPath Studio, the type is declared when the argument is created. The
types of arguments are: string, number, array, date/time, Boolean, and data
tables.
• Default Value: Value is the data that an argument holds. (Must be provided in
English)
31 | P a g e
Slide 28
Arguments Panel
• Introduction to Arguments Panel
• Managing arguments
This section gives an overview of the Arguments panel and how to manage
arguments.
32 | P a g e
Slide 29
Studio has an Arguments Panel that enables the users to create arguments and
modify them. Whenever a user changes the name of an argument in this panel, it
automatically gets updated at all occurrences in the current file.
The panel is located at the bottom right side of the Activities panel and it is hidden by
default. When clicked, the panel opens and displays the existing arguments in the
project and allows the user to modify them.
The Arguments Panel consists of fields through which the users can define the
different properties of an argument. It has the following fields:
• Name
• Direction
• Argument Type
• Default Value
33 | P a g e
Slide 30
Managing Arguments
In Studio, a user can create arguments from the Arguments Panel through the ‘Create Argument’
option.
Step 04
Specify a default
value
In order to manage the arguments in UiPath, the users may need to perform several
actions on them. These are:
• Creating Arguments
• Removing Arguments
1. Creating Arguments
While creating an argument, its properties need to be initialized. The user can
create an argument by following these steps:
• Define a name for the argument.
• Set the direction of the argument (In, Out, In/Out).
• Choose the type of argument.
• Now choose a default value.
2. Removing Arguments
34 | P a g e
A user can follow either of the following steps to remove an argument:
35 | P a g e
Slide 31
Argument Directions
• Introduction to Argument directions
36 | P a g e
Slide 32
In
01 • Argument can only be used within a given project
Out
02 • Argument can be used to pass data outside a given project
In/Out
03 • Argument can be used both within and outside a project
Argument direction tells the applications where the information stored in them is
supposed to go, i.e., it specifies the direction from/to which the data is passed.
Argument names should be prefixed for easy identification of the argument direction,
such as in_FileName, out_TextResult, io_RetryNumber.
37 | P a g e
Slide 33
Classroom Exercise
Demonstrate how to create and initialize arguments through the Arguments panel.
• Go to Arguments panel.
• Click Create Argument and enter two arguments named in_intFirstNumber and
in_intSecondNumber.
• Select a Direction for the arguments. You can choose between four available
options:
o In takes value of an argument inside the workflow
o Out takes value outside the workflow.
o In/Out takes value inside or outside the workflow
• For these two arguments, select Direction as In and Argument type as Int32. Int32
is for integers.
• Create a third argument called out_intSum, select Direction as Out, and Argument
Type as Int32.
• Drag and drop an Assign activity in the Designer panel.
• Enter out_intSum in the first text area and
in_intFirstNumber+in_intSecondNumber in the second text area.
• Right click on the Sequence container and select Extract as Workflow from the
context menu.
• Enter SumTwoNumbers as workflow name and click Create.
• Go to the Main file, and create three variables:
o An integer variable intFirstNumber with Variable type as Int32 and Default value
as 5
o An integer variable intSecondNumber with Variable type as Int32 and Default
value as 10
o An integer variable intResult with Variable type as Int32.
• Click Import Arguments within Invoke workflow, and pass the variables for each
argument value:
38 | P a g e
o intFirstNumber for in_intFirstNumber
o intSecondNumber for in_intSecondNumber
o intResult for out_intSum
• Drag and drop a Message box activity below Invoke workflow and enter intResult
in the text area.
• Run the file to get the output as 15.
39 | P a g e
Slide 34
40 | P a g e
Slide 35
Arguments Variables
Argument stores data and passes it between Variable stores data and passes it between
workflows 01 activities
Arguments and Variables are quite similar to each other. They both are used to store
information of a particular data type and pass it.
• Argument stores data and passes it between workflows. Variable also stores data
but passes it between activities.
• An argument can be used across multiple workflows (direction to be defined) but a
variable is limited to the workflow in which it was defined.
• An argument is created & modified through Arguments Panel whereas a variable
is created & modified through Variables Panel.
• An argument is defined by properties: Name, Direction, Type, Default Value
whereas a variable is defined by Name, Type, Scope, Default Value.
41 | P a g e
Slide 36
Practice Exercise
• Ask user to input two numeric values and store them in two variables.
• Swap values of both the variables with each other using a third variable.
• Display initial and swapped values of both the variables in the Output panel.
Process Overview
• START
• Use Input Method activity to receive two numeric values from the user
• Store the received values in two integer variables called First_Input_Value, and
Second_Input_Value
• Declare a third integer variable called Swapping_Support_Variable
• Use Assign activity to assign value of First_Input_Value to
Swapping_Support_Variable
• Use second Assign activity to assign value of First_Input_Value to
Second_Input_Value
• Use third Assign activity to assign value of Second_Input_Value to
Swapping_Support_Variable
• Use Write Line activity to display initial and final values of First_Input_Value and
Second_Input_Value in the Output panel
• STOP
42 | P a g e
Slide 37
Summary
02 Variables Panel
03 Scope of a Variable
04 Arguments
05 Arguments Panel
06 Argument Directions
43 | P a g e