UiPath Studio - Variables and Arguments


Advertisements

In this chapter, let us understand how to deal and work with variables and arguments in UiPath, and the concepts involved.

Managing Variables in UiPath Studio

Variable may be defined as the symbolic name associated with a value that may change. In UiPath studio variables are of different types and are used to store multiples type of data ranging from generic value, text, number, data table, time & date.

One important use of variables is that we can control the number of times the body of a loop is executed because the value of variables can change.

The Variable Panel

As the name suggests, the variable panel is used to create variables and enables us to make changes to them. The following screenshot will give an insight about the variable panel −

Variable Panel

In the above screenshot, you can notice that there are four fields namely Name, Variable Type, Scope and Default in the variable panel.

The four fields are explained as given below −

Name

It is a mandatory field. We must have to give a name to the variable. Suppose if you are not giving any name, then UiPath studio will generate one automatically. It is recommended that we follow naming conventions, as discussed in the previous chapter, while naming a variable.

Variable Type

It is also a mandatory field which enables us to choose the type of variable. We can choose among the options: Boolean, Int32, String, Object, Generic Value, Array of [T] and Browse of Types from the Property panel itself. If you do not choose any type, UiPath studio will consider it as a string.

Scope

It is also a mandatory field which shows the area in which the variable is available. For example, if you choose the activity type Sequence then the scope of the variable would be Sequence and so on.

Default

It is an optional field which shows the default value of a variable. For example, the default value for a variable of type Int32 is 0.

Types of Variables

The following are the types of variables that we can use in UiPath Studio.

  • Text variables − As the name suggests, such type of variables can store only strings. For example, if you want to store information like name, lastname, usernames etc., then text or string variables is the option you have to choose.

  • Boolean variables − These are also called True or False variables. It has only two possible values: true or false.

  • Integer variables − As name suggests, such kind of variables can store only integer or Int32 values i.e. integer information. They are also called Number variables.

  • Array variables − If you want to store multiple values of the same type then the array variable would be suitable. You can store as many types of arrays as there are types of variables in UiPath.

  • Date and Time variable − As the name suggests, this kind of variable enables us to store information about any date and time.

  • Data Table variables − These types of variables store big piece of information. It acts as a database or spreadsheet with rows and columns. For example, if you want to extract information from a website and want to store it in a spreadsheet, then you can choose data table variable.

How to Create Variables?

Once you choose at least one activity in the designer panel of UiPath studio, you can create a variable with the help of the following two methods −

  • By using option from Context menu − As you know after right-clicking the activity, the context menu appears. From this context menu you can choose the option Create Variable. The following screenshot will give insight of this −

Variable Panel
  • By using Variable Panel − Another way to create a variable is Variable Panel. First, we need to click on variable panel from the designer tab. Then variable panel would be displayed. Now, click create variable line to create a new variable. The variable panel has already been discussed in detail in the previous section.

How to Remove Variables?

We can also delete the variables we have created in the previous section, using any of the following two methods −

Method 1

Go to variable panel and right click the variable you want to delete. After clicking the “Delete” option, you can delete the selected variable.

Method 2

Go to variable panel and select the variable you want to delete. Now press delete button from keyboard and the selected variable will be deleted.

Managing arguments in UiPath Studio

Arguments, resembling variables, are used to pass data from one workflow to another. They can store data dynamically and pass it on. One difference between variable and argument is that variables pass data to other activities while arguments pass data to other workflows.

In UiPath studio, arguments are of different types hence we can create different types of arguments like Generic value, text, number, data table, object, Boolean. An important point about arguments is that they have specific directions that tell the application where the information stored is supposed to go. The directions can be In, Out, In/Out, Property.

The Argument Panel

As the name suggests, the argument panel is used to create arguments and enables us to make changes to them. The following screenshot gives an insight about the argument panel −

Argument Panel

In the above screenshot, you can notice that there are four fields namely Name, Direction, Argument Type and Default in the variable panel. The following is the explanation about them −

  • Name − It is a mandatory field. We must have to give a name to the argument. Suppose if you are not giving any name then UiPath studio will generate one automatically. It is recommended that follow naming conventions, discussed in previous chapter, while naming an argument.

  • Direction − It is also a mandatory field which enables us to select a direction for our argument. We can choose from following four kind of directions −

    • In − This direction means that the argument can only be used within the given workflow.

    • Out − This direction means that the argument can be used to pass data outside the given workflow.

    • In/Out − This direction means that the argument can be used within and outside the given workflow.

  • Property − This direction is not in use currently.

  • Argument Type − It is also a mandatory field which enables us to choose the type of argument. We can choose among the options Boolean, Int32, String, Object, Generic Value, Array of [T] and Browse of Types from the Property panel itself. If you do not choose any type, then UiPath studio will consider it as a string.

  • Default − It is an optional field which shows the default value of an argument.

How to Use an Argument?

Let us take an example to understand how we can use arguments.

Example

In this example, we will create two separate sequences: one for assigning a value to an argument and the other for invoking it and displaying the value in a message box.

We need to follow the following steps to implement this −

Step 1 − Drag & drop a sequence in the UiPath studio designer panel.

Step 2 − Click Arguments panel and create new argument say InputValue of String type having Out direction.

Step 3 − Now, drag & drop an Assign activity to the designer panel.

Step 4 − We want to give the value to Assign activity same as the value of InputValue argument. For this purpose, go to the Properties Panel of Assign activity and write InputValue in the To field.

Step 5 − Next, write any message say "Example of using an argument!!" in the Value field under Properties panel of Assign activity.

Till now, this implementation will look like as follows −

Example Argument1

Step 6 − Next, under the Design tab from New drop down menu choose new Sequence for designer panel.

Step 7 − For this create a new variable named strOutputValue by clicking on the variable panel.

Step 8 − Now, drag & drop an Invoke Workflow File activity to the Designer panel.

Step 9 − Next, browse for previously created sequence by clicking on the Browse (…) button on Invoke Workflow File activity.

Step 10 − We want to import the arguments in this activity. Hence click the Import Arguments button. It will open Invoke Workflow's Arguments window. Now in its Value filed add strOutputValue variable and click OK button.

In this way the value from it will be stored in the current project through strOutputValue variable. It can be seen in the following screenshots:

Example Argument2

Example Argument3

Step 11 − Next, add Message Box activity under Invoke Workflow File activity to the Designer panel and write a message “Thanks” in its text field.

Step 12 − Press Run(F5) button and it will give following output −

Example Argument4
Advertisements