Assign Value to a Variable If

Verb: setVarIf

Assigns a value to a variable if a specified condition is met.

Syntax

setVarIf --variablename(String) [--value(String)] --left(Variant) --operator(ConditionalOperators) --right(Variant) [--negate(Boolean)]

Inputs

Script Designer Required AcceptedTypes Description
--variablename Variable Required Text Variable to which the value is assigned if the specified condition is met.
--value Value Optional Text Value that should be assigned to the variable.
--left Left operator Required Any Value that is used to evaluate the condition.
--operator Operator Required ConditionalOperators Rule that is used to evaluate the condition as True or False. Options:
  • Begins with
  • Contains
  • Ends with
  • Equal to
  • Greater than
  • Greater than or equal to
  • Is empty
  • Is null
  • Is null or empty
  • Is true
  • Less than
  • Less than or equal to
  • Matches
  • --right Right operator Only whenOperator is Equal_To, Greater_Than, Greater_Than_Equal_To, Less_Than, Less_Than_Equal_To, Contains, Ends_With, Begins_With, Matches Any Value that is used to evaluate the condition according to the Left operator and Operator.
    The value should be of the same type as the Left operator.
    --negate Negate Optional Boolean When enabled, negates the rule defined at Operator.

    Example

    Example 1: The Assign Value to a Variable If command assigns the value "IBM" to the variable, if it is empty, which is the condition defined at Operator.

    defVar --name companyName --type String
    defVar --name emptyCompanyName --type String --value "IBM"
    setVarIf --variablename "${companyName}" --value "${emptyCompanyName}" --left "${companyName}" --operator "Is_Empty"
    logMessage --message "${companyName}" --type "Info"
    // Returns: IBM
    

    Example 2: The Assign Value to a Variable If command assigns the value "1733539173" to the variable, if it already contains the text "IBM".

    defVar --name phoneNumber --type Numeric
    defVar --name assignPhoneNumber --type Numeric --value 1733539173
    defVar --name name --type String --value "IBM"
    setVarIf --variablename "${phoneNumber}" --value "${assignPhoneNumber}" --left "${name}" --operator "Contains" --right IBM
    logMessage --message "${phoneNumber}" --type "Info"
    // Returns: 1733539173
    

    Example 3: The Assign Value to a Variable If command assigns "IBMAutomation" to the "company" variable if this variable holds the text "RPA".

    defVar --name firstCompanyName --type String --value IBM
    defVar --name secondCompanyName --type String --value Automation
    defVar --name company --type String --value RPA
    setVarIf --variablename "${empresa}" --value "${firstCompanyName}${secondCompanyName}" --left "${company}" --operator "Equal_To" --right RPA
    logMessage --message "${company}" --type "Info"
    // Returns:  IBMAutomation
    

    Remarks

    If Value is empty, the variable defined at Variable will also be empty.

    See Also

  • Assert Condition
  • Else If
  • End Do-While
  • Go to If
  • Run Subroutine If