Define Variable

Defines a variable as an input or output variable, specifying the "Variable Type".

Command availability: All offerings

Script Syntax

IBM RPA's proprietary script language has a syntax similar to other programming languages. The script syntax defines the command's syntax in the script file. You can work with this syntax in IBM RPA Studio's Script mode.

defVar --name(String) --type(String) [--innertype(String)] [--value(Variant)] [--parameter(Boolean)] [--output(Boolean)] [--required(Boolean)]

Dependencies

You can only create variables either by referencing the command through the Script mode or by using the New variable button on Design mode.

Input parameter

The following table displays the list of input parameters available in this command. In the table, you can see the parameter name when working in IBM RPA Studio's Script mode and its Designer mode equivalent label.

Designer mode label Script mode name Required Accepted variable types Description
Name name Required Text Name of the variable, being used whenever it is necessary to refer to it.
Variable Type type Required Text Data type of the variable.
Inner Type innertype Optional Text Inner data type of variables of type: list, row, stack or data dictionary.
Value value Optional Text Initial value assigned to a variable as its default value. It is possible to assign values that the variable does not consider as the default by using the Set Variable (setVar) command.
Script Input Parameter parameter Optional Boolean When enabled, defines a variable declared as a "Script Input Parameter". When a request of the respective script happen, this variable receives a value.

By receiving a value, the script generates a copy of the variable without changing the original data of the calling environment.
Script Output Parameter output Optional Boolean When enabled, defines a variable declared as a "Script Output Parameter". The variable defined as "Script Output Parameter" return values from the respective script. As it is a reference parameter, it allows the changed values in the variable to persist in the calling environment.
Required required Only visible when the "Script Input Parameter" parameter is enabled Boolean When enabled, the parameter set as the "Script Inputer Parameter" becomes required.

Example

Example 1: Creates a "Boolean" variable without passing the initial value. So, by default, the initial value is "False".

defVar --name booleanVariable --type Boolean
logMessage --message "Boolean Variable Content: ${booleanVariable}" --type "Info"
// Result: Variable Content: False.

Example 2: Creates a "Number" variable with the initial value of "546548".

defVar --name numericVariable --type Numeric --value 546548
logMessage --message "Numeric Variable Content: ${numericVariable}" --type "Info"
// Result: Numeric Variable Content 546548.

Example 3: Creates a "Stack" variable that has the internal type "Text", with the initial values โ€‹โ€‹of "Mary, Jhon, Liry, Lucy, Klaus".

defVar --name stringStack --type Stack --innertype String --value "[Mary, Jhon, Liry, Lucy, Klaus]"
logMessage --message "String Stack Content: ${stringStack}" --type "Info"
// Result: String Stack Content: [Klaus,Lucy,Liry,Jhon,Mary].

๐Ÿ›ˆ Remember: The only function of the Log Message (logMessage) command is to show the value of the variables in the console, with no other function in relation to the declaration of variables.