If
Runs a block of commands if the defined condition is met.
Command availability: IBM RPA SaaS and IBM RPA on premises
Dependencies
Terminate the command block with the End If (endIf
) command.
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.
if --left(Variant) --operator(ConditionalOperators) --right(Variant) [--negate(Boolean)]
Input parameters
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 |
---|---|---|---|---|
Left operand | left |
Required |
Any |
Value used to evaluate the condition. |
Operator | operator |
Required |
ConditionalOperators |
Rule used to evaluate the condition. For more information, see operator parameter options. |
Right operand | right |
Required when Operator 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 compared to the Left operand to evaluate the condition. |
Negate | negate |
Optional |
Boolean |
Negates the rule defined in Operator. |
operator
parameter options
The following values are supported for the Operator expression that evaluates the condition.
- 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
Example
Example 1: A student's average is stored in a numeric variable. The student can only participate in the draw if the average is greater than 7.
defVar --name studentAverage --type Numeric --value 8
if --left "${studentAverage}" --operator "Greater_Than" --right 7
messageBox --title Grade --text "Congratulations! You can participate in the draw!" --icon "Information" --buttons "OK" --defaultbutton "FirstButton"
endIf
logMessage --message "${studentAverage}" --type "Info"
// Checks student average and reports you can participate in the draw, as the value is greater than 7.
Example 2: Similar to the previous example, now using the Negate parameter. In this case, the message about the draw does not appear.
defVar --name studentAverage --type Numeric --value 8
if --left "${studentAverage}" --operator "Greater_Than" --right 7 --negate
messageBox --title Grade --text "Congratulations! You can participate in the draw!" --icon "Information" --buttons "OK" --defaultbutton "FirstButton"
endIf
logMessage --message "${studentAverage}" --type "Info"
// Checks value of studentAverage, but does not show message since value is greater than 7.