Skip to main content


         This documentation site is for previous versions. Visit our new documentation site for current releases.      
 

Defining expressions in Declare Expression rules

Updated on May 31, 2022

Define how your application calculates target properties by building expressions. When you build expressions, you create relations between properties so that an application can automatically update property values at run time. As a result, you increase the level of automation and flexibly respond to changing circumstances.

For example, you can create a Declare Expression rule that automatically calculates shipping costs based on the total weight of all items that a customer orders in an online shop. When the customer adds items to the order and the total weight changes, a Declare Expression rule automatically updates the shipping costs.
Before you begin: Create a Declare Expression rule. For more information, see Creating Declare Expression rules.
  1. In the navigation pane of Dev Studio, click Records.
  2. Expand the Decision category, and then click Declare Expression.
  3. In the list of instances of declare expressions, open the instance that you want to edit.
  4. Optional: To provide additional information about the rule, on the Expressions tab, in the Overview section, enter a brief description:
    1. In the Description field, briefly explain the purpose of the rule.
      For example: Enter This declare expression calculates the tax value that is 6% of the total price of all items in the shopping cart in an online shopping application.
    2. In the Usage field, briefly explain the scenarios and elements of your application where the declare expression applies.
      For example: Enter This declare expression calculates the tax value in the checkout page of a shopping application.
    Tip: Providing additional information about a declare expression is very useful to quickly share details of the rule with other developers.
  5. In the Build Expressions section, click Add condition.
  6. In the IF field, enter or select a property to evaluate at run time.
    The list includes properties from the Apply To class that you selected during rule creation. For more information, see Creating Declare Expression rules.
  7. In the list of comparators, select a comparator to apply during property evaluation.
  8. In the text field, provide a property to evaluate against the property from the IF field.
  9. Optional: To define more conditions, click Add a row, add a condition before or after the current condition, and then repeat steps 6 through 8.
    Result: By default, the system groups conditions by using the AND comparator. At run time, your application applies the result after all the conditions with the AND comparator evaluate to true.
  10. Optional: If you have multiple rows, to apply the result of the expression when any of the rows evaluates to true, click AND, and then click OR.
    For example: When the rows include price values of different items that a customer can add to an online shopping cart, and you select an OR comparator, the application applies the result of the expression when the customer adds any of the products to the shopping cart.
  11. In the Then set row for your target property, define how the declare expression determines the target property:
    • To determine the target property as a result of a string, in the list, select Value of, and then, in the text field, enter the string that calculates the property.
    • To determine the target property as a result of a decision tree, in the list, select Result of Decision Tree, and then, in the text field, enter a decision tree to compute at run time.
    • To determine the target property as a result of a decision table, in the list, select Result of Decision Table, and then, in the text field, enter a decision table to compute at run time.
    • To determine the target property as a result of a map value, in the list, select Result of Map Value, and then, in the text field, enter a map value to evaluate at run time.
  12. Optional: To add more conditions to the expression, click Add condition, and then repeat steps 6 through 11.
    Note: If you create multiple conditions, at run time, processing stops after your application determines the first expression that evaluates to true.
  13. In the Set row for the target property, provide that you want the system to apply if all the conditions evaluate to false:
    • To determine the target property as a result of a string, in the list, select Value of, and then, in the text field, enter the string that calculates the property.
    • To determine the target property as a result of a decision tree, in the list, select Result of Decision Tree, and then, in the text field, enter a decision tree to compute at run time.
    • To determine the target property as a result of a decision table, in the list, select Result of Decision Table, and then, in the text field, enter a decision table to compute at run time.
    • To determine the target property as a result of a map value, in the list, select Result of Map Value, and then, in the text field, enter a map value to evaluate at run time.
  14. Click Save.
For example: The following figure shows a Declare Expression rule that calculates a tax value in a shopping application when a customer reaches the Checkout page. Based on the prices of three types of items, the declare expression applies 6% of the total price as a tax. At run time, the declare expression updates the target property, which is a tax value, every time the user changes the quantity of items in a shopping order, because the total price changes as well. If the customer adds items with prices other than the prices that are included in the declare expression, the application calculates the tax value as 10% of the total price.
Sample declare expression
A declare expression that calculates a tax value.

Have a question? Get answers now.

Visit the Support Center to ask questions, engage in discussions, share ideas, and help others.

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.com is not optimized for Internet Explorer. For the optimal experience, please use:

Close Deprecation Notice
Contact us