How to pass variables as UiPath arguments example
In UiPath, a variable has scope within the sequence in which it is defined and any sub-block that sequence contains. However, a variable defined in one sequence or workflow cannot be referenced directly in another. UiPath variable scope does not cross a workflow’s boundaries.
So how do you use a variable defined in one workflow in another? You’ll need to configure a UiPath argument. The UiPath argument allows a variable’s value to be copied from one workflow to another.
UiPath argument directions
There are three types of argument directions in UiPath Studio:
- In arguments;
- Out arguments;
- In/Out arguments.
To pass a value from one sequence to another, use the In direction.
If you create a variable in a workflow and want the value of that variable sent to another workflow, use the Out direction.
Finally, to receive the value of a variable, change it and update the workflow that passed it in, use the In/Out direction.
How to create UiPath arguments
To create a UiPath argument, follow these steps:
- In the workflow that either gets passed in or passes out data, create a variable in the Arguments panel.
- Give the argument a name.
- Set the direction of the argument.
- Set the argument’s data type.
- In the calling program, map the argument to a variable or a literal value.
Once the argument is mapped it will behave exactly the same way a variable would. You can include the argument in calculations; you can concatenate the argument with other variables and arguments, and you can specify the argument as a value in the properties tab of an activity.
UiPath argument naming conventions
To distinguish UiPath arguments from variables, a special naming convention is recommended. Depending on the direction, the argument must be prefixed with either in, out or io. The prefix is followed by a snake_case underscore, and then the argument itself is named using Pascal case. Or to put it more simply, argument should start with either in_, out_ or io_.
Generally speaking, variables are not visible outside the activity in which they are defined. To overcome this limitation and make it possible to pass variables between workflows and flowcharts, you must use UiPath arguments.