Pega - RULE CIRCUMSTANCE - Interview Q&A

How do you make one rule behave differently for different customers, countries or products without writing a mess of if statements? Pega's answer is circumstancing: you keep one base rule and add variants that take over only when a condition matches.

What a circumstance is

A circumstance is an optional qualification you can add to almost any rule. A rule with a circumstance is a circumstanced rule, and it is always based on an unqualified base rule. When Pega looks for a rule to run, it compares the circumstance property and value on the rule with the value on the clipboard at that moment. If they match, the circumstanced rule is used. If not, the base rule runs.

Single and multivariate circumstancing

  • Single: one property and one value, such as .CustomerTier = Gold.
  • Multivariate: several properties and values combined, such as .CustomerTier = Gold and .Country = UK. It matches only when all of them match.

How to create one

  1. Create the normal base rule, with the circumstance fields left blank.
  2. Use Save As and fill in the circumstance property and value to create the variant.
  3. If the base rule is qualified by an Applies To class, the variant must use the same class or a subclass.
  4. Change the variant to say what should be different, and leave the rest as it is.

A worked example

A bank has a decision table GetInterestRate that returns 6 percent by default.

  • A circumstanced version for .CustomerTier = Gold returns 5 percent.
  • Another for .CustomerTier = Gold and .Country = UK returns 4.5 percent.

When a Gold customer in the UK applies, the most specific matching version runs. A Silver customer gets the base rule. No activity changed, and no one needed to add a new if statement.

When not to use it

  • Circumstances hide behaviour. A developer reading the flow does not see that a different rule ran. Document each one.
  • Too many variants become hard to maintain. If a rule has more than a handful, consider a decision table with the variation as a column.
  • If the variation is by product or country and needs its own ruleset and version, consider a separate ruleset instead.

Interview tip

Say: "A circumstance lets one rule have variants selected at run time by property values, using a base rule and circumstanced copies." Then give the tier or country example. See also decision rules and the Pega Basics label.

No comments:

Post a Comment