Declarative Rules in Pega

  • A Declarative Rule is an instance in a class derived from the Rule-Declare- class
  • You can establish required relationships among properties
  • Process Commander automatically invokes that rule whenever appropriate
  • Allow for dynamic processing of property values
    • Do not need to be explicitly called
    • Are not run in a sequential fashion
  • System manages re-evaluation when it detects change
  • Recalculation occurs
    • At the conclusion of Input Processing. When the form is submitted
    • At the end of each activity step, after invoking the method but before transition step
    • During the flow execution, as control advances from one task to another
  • Best practice
    • Create a Declare Expressions rule instead of using a Property-Set method in an activity.
    • Use a Constraints rule instead of a field validation rule.
  • As far as PRPC is concerned one of the guardrail says that calculate and edit declaratively, not procedurally
  • Declarative rules need / should not be refereed from any rule. They are always in force. The primary benefit of declarative processing is that the system, rather than the developer, controls when computations are processed

Types of Declarative Rules:

  1. Expression – Instance of Rule-Declare-Expression
    • Rule-Declare-Expressions : R-D-E ( Rule-Declare-Expressions ) can be created for properties and will have typically same name of the property.
    • R-D-E facilitates automatic computation of the property value, basing on changes of other property values.
    • The evaluation of the Declare Expressions is done in two ways.
      • Forward Chaining
      • Backward Chaining
    • Ex: Area = Length * Breadth
    • What decides the forward chaining / Backward chaining ? : The “Target Property Data “ field in declare expressions decide this:
      • Whenever inputs change – Forward Chaining
      • When used, if no value present – Backward Chaining
      • When used, if Property is missing – Backward Chaining
      • Whenever used – Backward Chaining
      • When applied by a Rule Collection – Procedurally
      • When invoked procedurally -Procedurally
  2. Constraints – Instance of Rule-Declare-Constraints
    • Constraints rules can provide an automatic form of property validation every time the property’s value is “touched”, in addition to the validation provided by the property rule or other means.
    • The system evaluates constraints automatically each time a property identified in a Constraints rule is changed.
    • Constraints use the forward chaining.
    • Examples:
      • Property cannot be negative
      • Property cannot be greater than a certain value
    • Can target more than one property in a single constraints rule
  3. OnChange – Instance of Rule-Declare-OnChange
    • Declare OnChange rules can be used to run an activity automatically whenever the value of a specified property changes.
    • This capability provides a form of automatic forward chaining. If you specify more than one property, they all must be on same page.
    • For example, we can create a declare onchange to call an activity that send a mail to employee when ever either HRA or Basic or SpecialAllowance are changed.
  4. Trigger – Instance of Rule-Declare-Trigger
    • Run/Executes an activity when instances of a specific class are created, updated, or deleted in the database.
    • For each Declare Trigger rule, Process Commander monitors database operations for objects of the Applies To class
    • For example, a Declare Trigger rule can execute an activity each time an instance of Data-Party-Person class is saved with a modified ZIP code
    • Triggers implements forward chaining
  5. Index – Instance of Rule-Declare-Index
    1. Declare Index rule is defined for defining criteria under which Process Commander automatically maintains index instances for faster access.
    2. Scenario: If you have a pagelist property(embedded property) in a database table. And, for reporting purpose, you want to expose that pagelist property. If you want to expose a pagelist property, you have to follow the below steps:
      • Create an index table(inherited from index- class) and keep the values of the pagelist property (which we want to expose)
      • Whenever a new record is inserted in to a main table, then we have to push the values of pagelist property to index table. Doing this for every record is impossible. To do this task, we create a Declare Index rule.
      • Declare Index rule is written on the pagelist property. Whenever the value of pagelist changes automatically, the values of the pagelist is copied to index table.
      • By joining main table and index table, we can easily generate reports on the embedded property values
    3. Note: We can create Index table and Declare Index rules by using the Optimizing tool. Just do right-click on the pagelist property and Optimize it. Automatically, one index table and one declare index rule will be created.

Comments or questions are welcome. Post in the comments box.

3 thoughts on “Declarative Rules in Pega

  1. Hi there! This is my first visit to your blog! We are a team of volunteers and starting a new project in a community in the same niche. Your blog provided us valuable information to work on. You have done a extraordinary job!

    1. Hi,
      Nice to hear those words from you. May I know, what project you are starting? Can you provide me more details, if you don’t mind. I will ping you on your email id too.

Leave a Reply

Your email address will not be published. Required fields are marked *