Skip to main content

Comparisons and expressions

Comparison

Pega Robot Studio provides simple logic decision operators that yield True or False to allow you to control the automation flow depending on the input. Comparison components accept a single value that is compared against a value that you assign during design. You can find the comparison components in the Work Flow > Decisions section of the Toolbox. 

A decision section of the Toolbox

For example, a customer support representative (CSR) of a banking company assigns a reward scheme to clients if their credit limit is greater than or equal to USD5000. Otherwise, it runs an automation that checks conditions to increase the credit limit. 

Screenshot showing the use of comparison design block in a real business scenario.

Comparison methods of automation variables

Automation variables have comparison methods dedicated to their types. Comparison methods, like the comparison components, accept a single value and compare it against the value assigned by the designer. Still, it takes fewer design blocks and is easier to read. To access comparison methods, drag the variable to the automation surface and select the required method to add a design block. 

To compare an automation variable of numeric types like integer, decimal, or double, use a comparison method, like in an example below.  

A screenshot showing how to use comparison method instead of design block.

Several comparison methods are available for string types, including StartsWith, EndsWith, IsNumber, IsUpper, or IsSymbol. You can also compare color and font type variables. 

For example, a banking company extends bonuses for gold credit card owners. The automation compares the credit card type against a defined pattern by using a StartsWith method.

Screenshot showing comparison methods for String type in a business scenario.

For more information about advanced comparison methods, see Data handling.

Switch

The Switch component enables you to establish conditional logic of events for a list or collection of inputs. This component works similarly to the Switch construct in Object-Oriented programming. Unlike comparison methods, the switch component allows you to check against a set of parameters and lists multiple courses of action, including a Default option if the other options are not chosen.

In the following image, an automation triggers when a user confirms their selection by clicking the button and specifies a different action for each selection.

An example automation that uses the switch component to decide on the next action after user's selection.
Note: A Switch component can handle various input types such as strings, integers, and enumerators, but it cannot handle Object types like the SelectedItem of a list box.  

StringSwitch component

The StringSwitch component is similar to the Switch component, but it operates on the string type input and offers more options to evaluate an input value. The StringSwitch design block has two parameters: CaseSensitive and MatchMode, which enable you to create more complex expressions for comparing the input value with the pattern.

For example, the customer support automation for the banking application uses the StringSwitch component to redirect the ticket to the proper department, depending on the claim title, as shown in the following figure.

An example automation that uses the StringSitch component to select the banking department.

Use the MatchMode parameter to adjust the string matching method; available options are: simple, contains, starts with, and ends with.

Check your knowledge with the following interaction.

Expressions

Expressions allow you to add equations to the automation. There are three types of expressions that are accessible from the Expressions section of the Toolbox: boolean, string, and numeric. 
Boolean expressions allow for control of the automation workflow by using the result of an equation. String and numbering expressions allow developers to create complex functions that are not handled easily by other Toolbox items. 

Boolean Expression

The Boolean Expression component of Pega Robot Studio allows you to add a logical statement that is either True or False. The Boolean Expression can evaluate double, integer, string, and boolean datatypes. Compared values should be of the same type; setting different data types for two parameters can invalidate the expression considering the type conversion. 

To add an expression to your automation, drag it to an automation surface and click the design block to enter the expression. Expressions do cover the basic comparison logic, but they can be extended into more complex logic by using C# boolean logical operators. Some valid expressions include:

  • a > b
  • a < b
  • a != b
  • a == b
  • a >= b
  • a <= b
  • (a + b) > c && (b > d)
  • (a * b) > (c + d) || d > (a / b)

If you use dynamic values to evaluate, use the data ports enabled after the addition of an expression, as in the following example:

Screenshot showing how to use boolean expression to compare card balance with the credit limit.

You can also provide a hard-coded value as the second parameter of the expression. 

The Boolean Expression component provides you with an option to make a decision in a workflow. You can right-click on the output data port of expression and select Make Decision. A decision design block appears on the screen and allows you to control the workflow by using the True or False logical paths. 

Screenshot showing the use of boolean expression in a business case scenario - comparing the transaction amount with credit limit.

 

String Expression

The String Expression component allows you to create an expression that manipulates the input string value, for example, concatenating two string variables. The input values can be dynamic or hard-coded data. In the case of hard-coded values, enclose the value in a quotation. You can also use C# String class notations for more complex expressions, such as a.Substring(1, a.IndexOf("f")).

In the following example, the String Expression creates a user's email in a banking domain.

Screenshot showing an example of using String expression to create a user email from the username.

Numeric expression

The Numeric Expression component allows you to perform standard mathematical functions such as addition, subtraction, multiplication, and division. You can also pass decimal values to the expression. The number of significant digits (precision) of decimal numbers is set using the Decimals property. 

In the example below, the Numeric Expression calculates a profit from a standard bank deposit of Robotic Banking.

Screenshot showing a use of numeric expression to calculate profit from banking investment.

 

Check your knowledge with the following interaction.


This Topic is available in the following Module:

If you are having problems with your training, please review the Pega Academy Support FAQs.

Did you find this content helpful?

Want to help us improve this content?

We'd prefer it if you saw us at our best.

Pega Academy has detected you are using a browser which may prevent you from experiencing the site as intended. To improve your experience, please update your browser.

Close Deprecation Notice