Declarative Rules Overview in Pega
Declarative Rules Overview in Pega
Pega has an internal declarative engine that utilizes abstract Java engine libraries for evaluation.
These libraries use a Directed Acyclic Graph (DAG) network to maintain the declarative
structure. The major difference between cyclic and acyclic graphs is that a cyclic graph can have
closed loops, whereas an acyclic graph has no loops.
In Pega we can write a business logic in two ways:
1) Structural processing: when you can create activity, data transform and other rules and
make sure you manually invoke them at the right places.
2) Declarative processing: you can use a set of declarative rules, to automatically compute
some activity rule using the declarative DAG network. Declarative rules can be called
business rules and can be delegated to business users.
Pega platform provides six types of declarative rules to support declarative processing.
➢ Declare expression (Rule-Declare-Expressions rule type)- mainly used to calculate
target properties when the depended properties change.
➢ Declare on change (Rule-Declare-OnChange rule type)- automatically executes an
action when the dependent property changes.
➢ Declare trigger (Rule-Declare-Trigger rule types)- automatically executes activities
or flow when an instance is created, updated or delated.
➢ Declare index (Rule-Declare-Index rule type)- automatically creates and maintain
indexes for embedded properties
➢ Constraints (Rule-Declare-Constraints rule type)- automatically enforce condition
and validation when referred.
➢ Data pages- also declare pages that can automatically load the data when referred.
(I’ve covered various declarative rules in Pega. Stay tuned—we’ll dive deeper into
Data Pages in an upcoming discussion!)
There is no need to call these rules manually.
Example: Total price= cost *Quantity, here if the input values changes(cost, quantity) the
total price also changes.
C=A+B
When A or B value changes C get calculated.
(It is very rare nowadays that we use backward chaining in the application processing)
We can configure a declare expression can be done in two places.
➢ Manually creating the declare expression.
➢ From case designer data modelling.
What is constrain ?
Constraints in Pega are declarative rules used to enforce conditions and validations on property
[Link] comes under decision category. When a property with an associated constraint is
referred to or modified, the rule automatically checks that the data meets the required condition.
This ensures data integrity and prevents invalid data from being stored or processed.
Example: If a rule specifies that Age must be between 18 and 65, every time someone enters an
age, Pega verifies it. If the value is outside the allowed range, an error message appears or the
data is rejected
Constraints in Pega ensure data integrity by automatically verifying that property values meet pre-defined conditions whenever they are accessed or modified. They function as declarative rules that enforce validation consistently across the application. For example, if an application requires a user's age to be between 18 and 65, the constraint ensures that any input outside this range generates an error message or rejection, thus maintaining data validity and preventing erroneous entries .
Declarative processing in Pega allows for automatic computation and rule enforcement via declarative rules such as declarative expressions, triggers, and constraints. This method uses a Directed Acyclic Graph (DAG) to maintain dependencies and automatically triggers changes when input data changes. In contrast, structural processing requires manual invocation of rules like activities and data transforms at specific points. Businesses might choose declarative processing for efficiency and consistency, as it reduces manual intervention and ensures immediate response to data changes. However, structural processing might be preferred for complex sequences that require precise control over execution order and conditions .
Declare Trigger rules function like sensors by constantly monitoring specific class instances for changes, such as creation, modification, or deletion. They automatically execute predefined activities once the conditions for these changes are met, similar to how a sensor detects environmental changes and initiates a response. For instance, in an order processing system, a trigger can automatically update the order status when payment is received, ensuring timely updates without manual intervention .
The Directed Acyclic Graph (DAG) enhances the declarative engine's functionality by structuring dependencies in a way that avoids cycles, ensuring calculations can be propagated in a predictable, non-recursive manner. This structure allows Pega's declarative engine to automatically manage and execute rules upon data changes without circular dependencies, facilitating efficient decision-making and data integrity within applications .
Forward chaining in Pega's declarative rules works by automatically recalculating dependent properties when input values change. For example, if a total price is calculated as cost multiplied by quantity, changes to cost or quantity automatically update the total price. Backward chaining, conversely, calculates values only when a dependent property is explicitly referred. For instance, if a discount is based on a coupon field, the discount is computed only when that field is checked. Forward chaining allows more dynamic updates, while backward chaining reduces computation by limiting when calculations are triggered .
The 'Declare On Change' rule is beneficial in scenarios where specific actions must be taken immediately upon changes to property values, such as updating a user interface or triggering additional calculations. This rule operates by implementing forward chaining: when a property changes, associated activities are executed automatically, allowing for responsive and dynamic application behavior. An example is adding a free gift to a shopping cart if the total cost exceeds a certain value, thereby enhancing user experience and operational efficiency .
Declare expressions in Pega facilitate dynamic computations by automatically calculating target properties based on expressions whenever dependent properties change, using either forward or backward chaining. These can be manually created, allowing precise control over the conditions and logic, or generated through the case designer, which provides a user-friendly interface for defining these expressions as part of a broader data model or business process, thereby improving efficiency and user accessibility .
Declarative processing rules in Pega contribute to agility in business operations by allowing automatic execution and enforcement of business logic without manual intervention. This automation reduces development time, decreases errors, and enables faster adaptation to changes as rules adjust automatically to new data patterns. In contrast, traditional programming requires explicit coding and testing of every condition and scenario, which increases overhead and slows down response to change .
Using Declare Index in Pega is advantageous because it automatically creates and maintains indexes for embedded properties, enhancing performance during search operations or when navigating relationships within large datasets. This automated indexing reduces the time and computational resources needed for data retrieval, thereby making applications more efficient and responsive, particularly in complex data environments .
Choosing backward chaining over forward chaining in declare expressions implies that calculations are deferred until the dependent property is explicitly referenced, reducing unnecessary computations and potentially improving performance in environments where such references are infrequent. This approach is suitable for applications where certain calculations are only needed conditionally or infrequently. However, it may lead to delayed updates if dependencies are frequently referenced, whereas forward chaining ensures immediate updates with every input change .