Case
Evaluates one or more conditions and runs a command block.
Command availability: IBM RPA SaaS and IBM RPA on premises
Dependencies
You can only use it with the When (when
) and Then (then
) commands.
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.
case [--name(String)] [--executeonce(Boolean)] [--priority(Numeric)] --switches(CaseSwitches) --minimum(Numeric) --maximum(Numeric) --quantity(Numeric) (Rule)=output
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 | name |
Optional |
Text |
Specify a name to the rules, labeling these conditions as a set of rules. |
Execute Once | executeonce |
Optional |
Boolean |
Executes the rule only once. |
Priority | priority |
Optional |
Number |
Specifies a priority among the defined rules. |
Options | switches |
Required |
CaseSwitches |
Condition evaluation options. |
Minimum | minimum |
Required when Options are AtLeast or Between |
Number |
Specifies the minimum number of conditions that must be met to run the block of commands. |
Maximum | maximum |
Required when Options is Between |
Number |
Specifies the maximum number of conditions that must be met to run the block of commands. |
Quantity | quantity |
Required when Options is N |
Number |
Specifies the amount of conditions that must be met to run the block of commands. |
options
parameter options
The following options are supported by this parameter:
Option | Description |
---|---|
Any | At least one condition must be true. |
All | All conditions must be true. |
None | None of the conditions must be true. |
Mutually Exclusive | Of all the conditions, only one can be true. |
N | You define how many conditions must be true. |
At Least | You define the minimum amount of conditions that must be true. |
Between | You define the minimum and maximum amount of conditions that must be true. |
Output parameters
Designer mode label | Script mode name | Accepted variable types | Description |
---|---|---|---|
Rule | output |
Rule |
Returns a rule with the parameters of the defined condition. |
Example
Example 1: The following example prints a message if at least one of the conditions is true.
defVar --name leftOperand --type Numeric --value 3
case --switches "Any"
when --left "${leftOperand}" --operator "Equal_To" --right 3
when --left "${leftOperand}" --operator "Less_Than" --right 3
when --left "${leftOperand}" --operator "Greater_Than" --right 3
then
logMessage --message "At least one of the conditions is true" --type "Info"
endCase
logMessage --message "End Case" --type "Info"
// Result: One of the conditions is true.
// End Case
Example 2: The following example does not run the block of code inside the block because none of the conditions is true.
defVar --name leftOperand --type String --value "The American flag is red, white and blue"
case --switches "CaseSwitchesAll"
when --left "${leftOperand}" --operator "Contains" --right red
when --left "${leftOperand}" --operator "Contains" --right white
when --left "${leftOperand}" --operator "Contains" --right purple
then
logMessage --message "All conditions are true." --type "Info"
endCase
logMessage --message "End Case" --type "Info"
// Result: End Case
Example 3: The following example shows how to run a block of code if the condition defined by the When command is not met.
defVar --name verifiedCase --type String --value Name
defVar --name leftOperand --type String --value leftOperandValue
defVar --name rightOperand --type String --value rightOperandValue
case --name "${verifiedCase}" --switches "CaseSwitchesAll"
when --left "${leftOperand}" --operator "Equal_To" --right "${rightOperand}"
then
logMessage --message "True verified condition." --type "Info"
otherwise
logMessage --message "False verified condition." --type "Info"
endCase