Declare Expression rules
Declare Expression rules automatically calculate values based on other values that are available in your application. When you include Declare Expression rules in calculations, you increase automation and efficiently reuse resources.
For example, you can use a Declare Expression rule to automatically calculate a tax amount for an order in an online shop, based on the prices of items that the order includes.Declare Expression rules use two methods of calculating values: forward chaining and backward chaining. Starting with Pega Platform version 8.3, Pega Platform automatically applies the most suitable calculation method to each business scenario.
Forward chaining
Forward chaining occurs when the target property changes because the input values in the calculation change. Consider a scenario in which a customer creates an order in an online shop by selecting items that sum up to $60. A shopping application calculates the tax value that is 10% of the order amount and updates the target property with the value of $6. When the customer adds another item to the shopping cart, the application adds the price of the new item to the calculation. Consequently, input values change. The application performs forward chaining and updates the target value, which is the tax amount, based on the updated input values.
Backward chaining
Backward chaining occurs when an application seeks values of input parameters to calculate a target property. For example, in an online shopping application, when a customer provides a code to get a discount on specific items in a shopping order, the application seeks properties that hold prices of the selected items, and then updates the total order amount. In backward chaining, target values remain unchanged if input values change, and the application performs calculation only after receiving a call for a target property.
Backward chaining directly corresponds to the Property-Seek-Value method. The Property-Seek-Value method can access the computational relationships among properties in a Declare Expression rule to identify source values that are needed to compute a missing property value.
Backward chaining is also applicable in the following specific scenarios:
- Some of the fields in the expression are from data pages that are outside of the current page structure. For example, consider a scenario in which you want to sum up values of multiple sales opportunities, but each opportunity is a separate and independent page.
- A declare expression invokes a function that has no parameter, such as calculateEmployeeCount(). In such cases with no parameter, change tracking does not happen and the system applies backward chaining.
Users are no longer required to explicitly specify forward or backward chaining. Users can switch to legacy expressions if they want to explicitly specify a change tracking method.
Category
Declare Expression rules are instances of the Rule-Declare-Expressions rule types that are part of the Decision category.
- Creating Declare Expression rules
Create Declare Expression rules to automatically calculate values in your application. Declare Expression rules take advantage of values that exist in your system to calculate values of target properties. As a result, you increase automation of calculations in your application.
- Defining expressions in Declare Expression rules
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.
- Specifying pages and classes for a declare expression
Define pages and classes that store properties to ensure that declare expressions can access these properties to correctly calculate values for your business scenario. As a result, you increase the level of automation in your application because automatic calculations can occur without user intervention.
- More about Declare Expression rules
This topic provides additional information about declare expression rules.
- Declare Expression form - Completing the Change Tracking tab
Complete this tab to determine the conditions that cause automatic recomputation of the expression. These conditions affect how often the computation on the Expressions tab is performed.
- Viewing the declarative network
Quickly gain insight into the relationships between declarative properties, which your system calculates automatically based on the value of other properties. By accessing the declarative network you can view and test declarative rules, which reduces processing errors and development effort.
Previous topic More about Constraints rules Next topic Creating Declare Expression rules