Skip to main content

Robot Task Activities - Conditions​

The Conditions activities choose which activities run next, based on a comparison or a value.

The Conditions category in the activity list, with the If (simple) and Switch activities


If (simple)​

Compares a left operand with a right operand, using the selected operator and type, then runs either the Then body or the Else body.

The If (simple) activity, with the Left operand, Operator, Right operand and Type fields and the Then and Else bodies

  • Left operand: the first value to compare; Variables are resolved first
  • Operator: the comparison to make
  • Right operand: the second value to compare; Variables are resolved first
  • Type: the data type both operands are converted to before the comparison: "Boolean", "Decimal", "Double", "DateTime", "Int16", "Int32", "Int64" or "String"
  • Then: the activities that run when the comparison is true
  • Else: the activities that run when the comparison is false

Either body may be left empty. Both operand fields accept VisualCron Variables, so you can compare a value read from a list, a cell or an earlier activity's Result variable.

The operators you can use depend on the Type:

  • "String": "Equal", "NotEqual", "Contains", "NotContains", "RegExMatch" and "RegExNoMatch"
  • "Decimal", "Double", "Int16", "Int32", "Int64" and "DateTime": "Equal", "NotEqual", "Larger", "LargerOrEqual", "Smaller" and "SmallerOrEqual"
  • "Boolean": "Equal" and "NotEqual"

Any other combination, and the "NotCheck" operator, makes the activity fail with an error. With a type other than "String", at least one operand must have a value, and a value that cannot be converted to the type also makes the activity fail. "String" comparisons are case-sensitive.

Using the RegExMatch operator​

The "RegExMatch" operator tests the left operand against a regular expression given as the right operand, so the Then and Else bodies act on a match or no match. "RegExNoMatch" is the reverse. The expression matches if it is found anywhere in the value, so add ^ and $ when the whole value must match. This is useful for validating data before it is used.

For example, to confirm that a date read from a data file is in MM-dd-yyyy format before entering it in an application that only accepts that format:

  • Left operand: the date value, for example {USERVAR(lvDateReformat|GetCell|{RPALOOP(a381|Iterations)}|Date|false)}
  • Operator: "RegExMatch"
  • Right operand: ^(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])-(19|20)\d{2}$
  • Type: "String"

That expression matches:

  • A two-digit month from 01 to 12
  • A - separator
  • A two-digit day from 01 to 31
  • A - separator
  • A four-digit year beginning with 19 or 20, giving a range of 1900 to 2099

The expression checks the format only. It does not reject a date that does not exist, such as 02-31-2024.

Records that match are processed in the Then body. Records that do not match fall through to the Else body, where they can be written to an exception log for manual correction. See Data Processing & Logging for the logging pattern.


Switch​

Evaluates a value and runs the case whose key matches the result. If no key matches, the Default activity runs.

The Switch activity, with the Expression field, the Default activity and the Add new case link

  • Expression: the value to evaluate; Variables are resolved first, and each case key is compared with the result
  • Default: the activity that runs when no case key matches
  • Add new case: adds a case, with a key and the activity that runs when the key matches

A key matches only when it is exactly the same text as the result, including upper and lower case.

warning

If no case key matches and no Default activity is set, the Switch activity fails with an error. Set a Default activity whenever the value can be something you did not plan for.

Switch is a cleaner alternative to a chain of nested If activities when you branch on one value with several known outcomes, such as a status code or a record type.


Tips​

  • Set the Type to match the data you are comparing. To compare numbers or dates as larger or smaller, use a numeric type or "DateTime": the "String" type supports only equality, contains and regular expression operators
  • A Result variable written by an earlier activity, such as File Exists, holds the text "True" or "False". Comparing it with the "String" type and "True" as the right operand works
  • Use the Display name property to describe what the condition tests, for example Check If Date Format Is Valid, rather than leaving the default name