Variables and Arguments are the main components of UIPATH development. It’s very difficult to imagine any of the development without using these components. They help with how data is collected, stored, processed, and passed between various activities and workflows, whereas Control flow is how the activities are executed throughout the process.
We will start by exploring how variables help us to store, process, collect and pass data within a workflow. Next, we will learn about how arguments and the invoke workflow activity help us pass data between workflows. Lastly, we will check out how we can use the, while, do while, for each, switch and parallel activities to control the order in which activities are executed within a process.
What are variables?
Variables are containers that can hold multiple data values of the same data type.
For Example: – Phone Number can be a variable that holds the value of “1234567891”.
The value of a variable can change through external input, anti-manipulation or passing from one activity to another.
What is the importance of variables in automation process?
Variables help us pass data from one activity to another. A value passing to the variable can travel through the end of the process. Any automation process would hardly be possible without using variables.
Different properties of Variables:
Variables are configured through their properties and can be set in the variables panel. The main properties in UiPath are: –
Name: – The Variable’s name is the unique ID and it defines the way it is displayed and used. It is always recommended that the variable name should be in Pascal Case. It should be as descriptive as possible to make your automation easy to read by other developers and to save time.
Type: – It define the nature of the variable and 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.
Default Value: – By using this option you can initialize your variable as per the variable type. Variable values can be changed throughout the process. For most variables, if no initial value is assigned when the variable is declared, there is default rule that assigns a value.
Scope: – By using this option, you can set the limit of the variable,as to which sequence or workflow the variable can be used. In some of the scenarios, there is no need for a variable out of the sequence, so we can only define the sequence name where we want to use that variable. It cannot exceed the workflow in which it was defined.
Different ways to Create Variables:
There are three main ways to create variables in UiPath:
From the Variable Panel: Navigate to the variables panel, Select the ‘Create Variable’ line and type in the name. Wherever needed, provide its name in the designer panel or in the desired properties field.
From Expressions: Variable can be created from expression 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 Variable panel.
From the Properties panel: In the property panel of any activity, select a field that can be edited, press Ctrl+K. The Set Var field is displayed. Fill the name and press enter. Check its type and scope in the variable panel.
Invoke Workflow and Arguments
What is a Workflow?
A workflow represents a small piece of automation that you can re-use in your projects. Under a workflow you can design and work with all the UiPath studio activities and it defines the flow of your automation. There are different types of workflowavailable in UiPath as per the need of the projects. Below are the names of the workflows available in UiPath: –
- State Machine
- Global Exception Handler
The importance of different workflow is to breakdown your process into smaller bits which can be more reliable, faster, and very useful methods.
This allows the independent testing of components, enables team collaboration and component reuse. Hence, most of the automation projects require the use of multiple workflows that come together to provide a solid business automation solution.
What is an Argument?
Arguments are similar to a variable:
- They can store the data dynamically
- They have the same data types
- They support the same methods and properties
The major difference between a variable and an argument is, they have additional property for the direction. Arguments can help to pass the data from one workflow to another. Arguments have specific directions: In, Out and In/Out. These directions tell the robot where the information stored in them is supposed to go.
IN: When the argument direction is “IN”, you are passing the values into the workflow. In other words, you can treat this as Input value of workflow.
OUT: When the argument direction is “OUT”, you are taking the values out from the workflow. In other words, you can treat this as an output of the process.
IN/OUT: When the argument direction is “IN/OUT”, you are passing the values into the workflow as an input and taking results from the workflow in the same argument.
Why are Arguments 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.
Different Ways to Create an Argument:
Argument names should be in PascalCase with a prefix stating the argument direction, such as in_DefaultTimeOut, in_FileName, out_TextResult, io_RetryNumber.
Different ways to create them are:
From the Argument Panel: Navigate to the argument panel, Select the ‘Create Argument’ line and type in the name. Wherever needed, provide its name in the designer panel or in the desired properties field.
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 created. In this way, the type is automatically received according to the activity.
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 arguments type is automatically generated depending on the selected property.