Guidelines for using variables
Variables store values at run time, and you reference them using their names. In IBM RPA, variables are strongly typed. For example, you can't assign a variable with type Text
to a variable of type Data Table
.
Keep assignments close to their usage
Assign values to variables by using the Set Variable (setVar
) or Set Variables (setVars
) commands
close to line in your script where you will use these variables. Avoid assigning values to variables that you will use only later in the code.
Be explicit when using input or output variables
Avoid using a variable as both the script's input and output variable. Variables should have only one purpose.
Use names to label constants
IBM RPA doesn't support constants definition. A constant is a variable whose value can't change during runtime.
Use a name convention to label variables as constants in your script.
Good example:
Avoid hardcoding values whose meaning is implicit or confusing
Hardcoding values whose meaning is implicit or confusing need comments to explain them. Avoid hardcoding values. Instead, use a constant.
Bad example:
Good example:
Keep your variable's purpose unique
Avoid using variables for different purposes. Using variables for generic needs can produce side effects and make your code harder to maintain or support.
Always remove unused variables from the script
You should remove any unreferenced variables from your script. Keeping them adds nothing to the script other than redundant lines of code.