Run Subroutine If
Runs a subroutine if a defined condition is met.
Command availability: IBM RPA SaaS and IBM RPA on premises
Dependencies
You must define a subroutine with the Start Subroutine (beginSub) 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.
gosubIf --label(String) [--assignments(String)] --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 |
|---|---|---|---|---|
| Name | label |
Required |
Text |
Name of the subroutine to run. Enter the name created with the Start Subroutine ( beginSub) command. |
| Assignments | assignments |
Optional |
Text |
Assignments to parameters within the subroutine and their values in the current execution context. |
| Left Operand | left |
Required |
Any |
Value used to evaluate the condition. If the defined variable is of type "Number", the initial position of its value is 0. |
| 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: Command configured to execute a subroutine if the numeric variable created is equal to 7.
defVar --name leftOperand --type Numeric --value 7
gosubIf --label subRoutine --left "${leftOperand}" --operator "Equal_To" --right 7
logMessage --message "End of execution." --type "Info"
beginSub --name subRoutine
logMessage --message "The condition is true. Subroutine executed." --type "Info"
endSub
Example 2: Similar to the previous one, however, with the Negate parameter enabled.
defVar --name leftOperator --type Numeric --value 7
gosubIf --label subRoutine --left "${leftOperator}" --operator "Equal_To" --right 7 --negate
logMessage --message " End of execution. " --type "Info"
beginSub --name subRoutine
logMessage --message "The condition is true. Subroutine executed." --type "Info"
endSub