Assign Variable

Verb: setVar

Assigns values to a variable.

Syntax

setVar --name(String) [--value(String)]

Inputs

Script Designer Required AcceptedTypes Description
--name Variable Required Text Variable to which values should be assigned.
--value Value Optional Text Value set to the Variable.

Example

Example 1: Sets 1000 as the value to a Number variable, defined with the default value "0".

defVar --name setVariable --type Numeric --value 0
setVar --name "${setVariable}" --value 1000
logMessage --message "${setVariable}" --type "Info"
// Result: 1000
// Value assigned to the variable.

Example 2: The value "text" is assigned to the Text variable "setVariable". The values "IBM" and "Automation" are assigned to two other text variables, "value1Set" and "value2Set", respectively. With the Assign Variable command, the values of "value1Set" and "value2Set" are concatenated and set to "setVariable", replacing its previous value.

defVar --name setVariable --type String --value texto
defVar --name value1Set --type String --value IBM
defVar --name value2Set --type String --value Automation
setVar --name "${setVariable}" --value "${value1Set}${value2Set}"
logMessage --message "${setVariable}" --type "Info"
// Result: IBMAutomation

Remarks

Only one variable is accepted in the Variable parameter.

The Value parameter can take more than one variable. In which case, the values are concatenated and assigned to the variable in the Variable parameter.

If the variable inserted in the Variable parameter already has a value, it is replaced by the new values set.

The inserted value must be of the same type as the variable.

See Also

  • Assign Value to a Variable If
  • Assign Variables
  • Imply
  • Set Key-Value Pair