Categories
RPA UiPath

Variables and Arguments in Studio (UiRPA part 4)

Variables and Arguments in Studio

Variables and Arguments in Studio

Overview

The Variables and Arguments in Studio course is an intermediate course that introduces you to how data is collected, stored, processed, and passed between various activities and workflows in UiPath Studio. You’ll learn how variables help us collect, store, process, and pass data within a workflow. You’ll learn about the various types of data and their conversion methods. You’ll also learn how arguments are used in UiPath and how the Invoke Workflow Activity helps us pass data between workflows. 

What you will learn in this course

  • Explain what variables are and what they are used for. 
  • Create and configure variables in an automation project. 
  • List the data types and apply the conversion methods of data types. 
  • Explain what arguments are and what they are used for. 
  • Use the Invoke Workflow File Activity to chain workflow execution and pass data through arguments. 
  • Differentiate between variables and arguments. 
  • Explain what arrays are and what they are used for. 

Important take outs

Variables and Arguments are basic units of storing information. They describe how data is collected, stored, processed, and passed between various activities and workflows.

Variables

Are containers that can hold multiple data entries (values) of the same data type. The value of a variable can change through an external input, data manipulation, or passing from one activity to another. 

Advancing with any automation process would be hardly possible without using variables. In Studio, variables are used to store multiple types of data. This data can be an integer, a boolean, a string, and many more data types.

Variables are configured through their properties. You can set them in the Variables panel. The Variables panel enables you to create variables and make changes to them.

The graphic shows the Variables panel and the main properties in UiPath: Name, Variable type, Scope, and Default.

Main Properties

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. PascalCase is a naming convention in which the first letter of each word in a variable is capitalized. Eg: ItemValue, LastName.
  • assigning meaningful names to the variables to accurately describe the usage of variables throughout the project.

The variable’s name is its unique ID and it defines the way it’s displayed and used. 

This is a mandatory field. If you don’t add a name to a variable, then, one is automatically generated.


Variable Type: It defines what kind of data is stored in the variable. In UiPath, the data type is declared when the variable is created.  The dropdown field provides quick access to the most used data types (seen below), but there are many more options available to you if you select “Browse for Types”. 

  1. Boolean
  2. Int32
  3. String
  4. Object
  5. System.Data.DataTable 
  6. Array of [T]
  7. Browse for Types

Note

  • Other types can be included in this list if previously used in Studio.
  • Browse for Types is an option that’ll open a dialog to select any supported type from the imported dependencies.

This is a mandatory field.


Scope: The part of the workflow in which the variable is called by name. A typical automation project consists of different workflows, nested, or connected in different ways.

The scope of a variable is defined by the name of the workflow in the automation project. Once the scope is defined, the variable can be used in that workflow and in all its children’s workflows.

In real-life automation scenarios, there are many variables in use. Making all of them unnecessarily global can cause efficiency issues as well as create conditions for confusion.

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’ll learn more about arguments shortly in the course.

The scope is a mandatory field.


Default: 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, then,  there’s a default rule that assigns a value. 

This is an optional field.

How to create a new variable

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.

From the body of an Activity

Variables can be created from the body of an Activity by pressing Ctrl+K in an input field that can accept a variable name. Alternatively, 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.

From the Properties panel

In the Properties panel of any activity:

  • Select a field that can be edited 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.

By performing right click in the input field of an activity

  • Right-click on any activity used in the sequence.
  • Select Create Variable option from the list of options.
  • This creates a new variable in the variable panel.
  • Fill in the name, type, and scope in the Variables panel.

What are data types?

Data Types describe what type of data a variable can hold.

For example, if the data type is Int32, then the variable must hold an integer number. Likewise, if the data type is a String, then the variable must hold a text.

Why are they important?

Variables and arguments in Studio need to have a specific data type defined. This makes sure that the right data format is applied at each stage of an automated process.

The base data types are basic data types such as integers, strings, dates, and so on. They include all the types that are part of any .NET programming language. 

  1. They’re used as variable values.
  2. They’re used as constant values.
  3. The processors can easily recognize them.

Data Types

String

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 with Strings in Studio.

Numeric

Used to store numbers. There are different sub-types of numerical variables. For a few examples:

  • Int32 – System.Int32 (signed integers): 10, 299, -100
  • Long – System.Int64 (long integers): 54354353430, -11332424D
  • Double – System.Double (allows decimals, 15-16 digits precision): 19.1234567891011

Boolean

System.Boolean: Used to store one of two values – True or False.

Collection

This category reunites all 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.

You’ll learn Arrays in the next lesson after arguments, and Lists and Dictionaries in more detail in the Data Manipulation with Lists and Dictionaries in Studio lesson.

DataTable

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.

You’ll find out more about DataTables in the DataTables and Excel Automation in Studio lesson.

Date and Time

  • 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.

GenericValue

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 aren’t sure what type of data we’ll receive, yet in general, using this is temporary.

While developing an automation process, there are situations where you are not sure what type of data is retrieved. In order to find out, you need to run a few tests using a variable with a broad enough spectrum that can catch any type of input. 

Conversion methods of Data Types

These are ways of changing an expression from one data type to another. For example, conversion of an integer to a string or vice versa.

Here’s a list of some of the conversion methods commonly used for data types.

Convert.ToString Method

This method converts the specified value to its equivalent string representation. 

It can be Int32 to String.

ToString(Int32, Int32) – Converts the value of a 32-bit signed integer to its equivalent string representation in a specified base.

Eg: StrVar = Convert.ToString(IntVar), StrVar = Int32Var.ToString(),

Convert.ToInt32 Method

This method converts a specified value to a 32-bit signed integer.

Convert.ToInt32(String) – Converts the specified string representation of a number to an equivalent 32-bit signed integer.

There’s another method to convert a string to an integer – CInt(String)

Convert.ToInt32(Double) – Converts the value of the specified double-precision floating-point number to an equivalent 32-bit signed integer.

Eg:

IntVar = Convert.ToInt32(StrVar)

IntVar = CInt(StrVar)

IntVar = Convert.ToInt32(DblVar) 

Double.ToString Method

This method converts the numeric value of this instance to its equivalent string representation. 

Eg: StrVar = DblVar.ToString – This method displays the string representations of a number of Double values. 

Double.Parse Method

This method converts the string representation of a number to its double-precision floating-point number equivalent.

Eg: DblVar = Parse(StrVar) 

Boolean.ToString Method

This method converts the value of this instance to its equivalent string representation (either “True” or “False”). 

Eg: BooleanVar.ToString()

Convert.ToBoolean Method

This method converts a specified value to an equivalent Boolean value. 

Eg: Convert.ToBoolean(Int32) – Converts the value of the specified 32-bit signed integer to an equivalent Boolean value. 

Convert DateTime to String

DateTime.Now Property – Gets a DateTime object that’s set to the current date, and time on this computer is expressed as the local time.

ToString(DateTime) –  Converts the value of the specified DateTime to its equivalent string representation.

Eg: Now.ToString(“dd-MM-yyyy”) or DateTimeVar.ToString(“dd-MM-yyyy”) – Provides the date format: 01-06-2022.

What is a workflow?

A workflow represents a relatively small piece of an automation project, typically executing a specific part of the process. Once built, it can be reused across different projects.

A workflow is made of Studio activities, interconnected through variables to form a routine. The routine typically has an input and an output. Basically, it defines the flow of 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.

Why is it important?

The fastest, most reliable, and most useful way of automating a process is to break it down into smaller bits. 

This allows for independent testing of components and enables team collaboration and component reuse. 

Hence, most automation projects require the use of multiple workflows that come together to provide a solid business automation solution.

What are the 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.

Why are they important?

Arguments are a key component when it comes to building more complex automation, where you need to store and use data between multiple workflows.

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.

Let’s check out the ways of creating arguments.

From the body of an Activity

Directly from the activity panel in an activity input field:

  • Right-click a field and select Create In Argument or Create Out Argument from the context menu. Alternatively, press Ctrl+M or Ctrl+Shift+M. 
  • The Set Arg field is displayed.
  • Fill in the name and press Enter. An argument is created.
  • Check its direction and type in the Arguments panel. 

Alternatively, from the Expression Editor:

  • Select a part of the expression and press Ctrl+M (for In arguments) or Ctrl+Shift+M (for Out arguments)
  • Then 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.

From the Properties panel

In the Properties panel of any activity:

  • Right-click a field that can be edited.
  • 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.

From the Arguments panel

  • Navigate to the Arguments panel.
  • Select the Create Argument line.
  • Fill in the name, direction, and type. A new argument is created.

Let’s list the differences between variables and arguments.

VariablesArguments
Used to pass data from one activity to another within a workflow.Used to pass data dynamically between automation.
Don’t have directions like In, Out, or In/Out.Do have directions like In, Out, In/Out. 
To create a variable press: Ctrl + K.To create an In Argument press: Ctrl +M.
To create an Out Argument press: Ctrl+Shift+M.
To create variables, there must be at least one activity in the Designer Panel.Arguments can be created if the Designer panel doesn’t contain any activity.
Variables aren’t used with the Invoke workflow file and Launch workflow Interactive activities.Due to their nature, arguments are used a lot in relation to the Invoke workflow file and Launch workflow Interactive activities.
Require a defined scope.Do not require a scope.

What are Collections?

If you have data entries that are similar, like invoice numbers, book names, and account numbers, and you want to group them together, then collections come in handy. They’re data types that allow the storage of entries of the same base data type as elements of one variable. This way, you can work both with all the objects in the collection variable and with each object. To make this work, the name of the collection variable and its position in the collection can identify the objects of a collection.

Let’s take the example of an Array of Strings:

StrArray = {“John”, “Paul”, “George”, “Ringo”}

StrArray(0) = “John”

The beauty of a collection is that each object is dynamic and can change its value as the workflow is executed. Moreover, some collection data types allow the unit holding the objects to grow or shrink accordingly.

Not all collection types can grow or shrink. In fact, arrays are the most common example of a collection with a fixed size, the one at creation.

You’re aware of the various types of Collections like arrays, lists, and dictionaries. In this lesson, you’ll learn in detail about arrays.

Hint: As a good case practice, arrays are used for defined sets of data (for example, the months of the year or a predefined list of files in a folder). Whenever the collection might require size changes, a List is probably the better option.

Hint: vbLf = visual basic line feed: This will add a new line in the text. Similar methods: Environment.NewLine, “\n”, “\r\n”. 

Facts

Ways to create a variable in UiPath Studio:

  1. Press Ctrl+K in an activity input field that requires a variable.
  2. Select the Create new Variable option in the Variables panel.
  3. Press Ctrl+K in an input field that requires a variable in the Properties panel.
  4. By performing right-click in the input field and selecting the create variable option.

PascalCase is a naming convention with first letter of each word of the variable name capitalized.

The list is the most encountered collection with dynamic size.

  1. Name – Defines how the variable will be identified.
  2. Type – Defines what kind of data can be stored in the variable.
  3. Scope – Defines the part of the workflow where the variable can be used.
  4. Default – Defines the value the variable is initialized with.

Tasks can be taken over by RPA robots:

  1. Start applications
  2. Capture data from text fields
  3. Make decisions based on predefined rules

The characteristics that make a process more suitable for RPA automation:

  1. Stable
  2. Rule-based
  3. Repetitive

  1. UiPath Studio – Designing automation workflows.
  2. UiPath Orchestrator – Managing and monitoring the execution of automation.
  3. UiPath Robot – Executing automation workflows.
  4. UiPath Automation Hub – Discovering automation opportunities and managing their journey from discovery to implementation.

GenericValue is a data type particular to UiPath and can store any kind of data, including text, numbers, dates, and arrays.

UserName  + ” is online” is the correct way to concatenate a string variable (UserName) with a string (” is online”).

Arguments are used to pass data from one workflow file to another in UiPath Studio.

Congratulation

Diploma of completion
Diploma of completion