CIRCUMSTANCING IN PEGA
Circumstance is a process by which we can specialize a rule, instead of creating new rules. By circumstancing an existing rule we can enable the circumstanced rule to follow a different process bases on some conditions. Circumstancing helps in making rules more reusable and makes it easier to maintain.
Circumstancing allows a developer to create a copy of the base rule - i.e., the circumstanced rule - which is applied at run time when the specified conditions are met. Circumstancing can be of 3 types bases on the conditions:
Single Property Circumstancing - based on one property
Multivariate Circumstancing - based on multiple properties
Time-varied Circumstancing - based on date range
Any existing rule that is to be circumstanced is called the Base Rule.
Let's see each type in detail.
1. Consider a section collecting customer information as follows.
2. On submitting this section, the base version of ShowDiscount section gets displayed.
Single Property Circumstancing
For Single Property CIrcumstancing, let us display the customers with "Category=Premium" a message with a discount in the ShowDiscount section.
1. Open the Base rule section - ShowDiscount. Click on the drop arrow beside Save button and select Specialize by Circumstance to circumstance the base rule.
2. Select Property for the Circumstance by option. This will display two fields where the Property and a Value (case-sensitive) must be entered.
3. In our case the Property is Category and the value is Premium.
4. Click on Create and open to create the new circumstanced rule variant and then click on Save.
5. Modify the rule as desired to display to Premium customers. Let us give them a 15% discount on all purchases.
6. Save and run the case. Select the category as Premium this time.
7. On submitting the section, the customer will be displayed with the circumstanced section, as their choice of is Premium.
Multivariate circumstancing allows the creation of a specialized rule based on multiple single-value properties.
In this case, let us create another circumstanced rule of ShowDiscount section based on the customer selection of two properties - Category and Country.
(If Category=Premium and Country=India, Let them have a 20% discount)
Multivariate circumstancing requires the creation of 2 additional rules:
To create a Circumstance Template
1. Navigate to Records >> Technical >> Circumstance Template. Click Create.
2. Provide a label for the circumstance Template and set the Apply to class. Click on Create and open.
3. The Edit Circumstance Template dialog is used to select multiple properties that will be used by the circumstance definition. 4. In our case, the Category and Country properties are added to the template. Click on Save.
To create a Circumstance Definition
1. Navigate to Records >> Technical >> Circumstance Definition. Click Create.
2. Provide a label for Circumstance Definition, Circumstance Template name and set the Apply to class. Click on Create and open.
3. On the Definition tab, a decision table shows the properties from the circumstance template as columns. The values in the first condition are "Premium" for .Category and "India" for .Country.
4. This means that whenever the configured properties match the provided values, the circumstanced rule will be selected during rule resolution.
Circumstancing the base rule for Multivariate Circumstancing
Note: If the same rule has been circumstanced by a property before, the earlier circumstance rule must be deleted first.A rule can not have multiple circumstance versions based on the same property (single and multivariate) as this could cause conflicts during rule resolution.
1. Open the rule that is to be circumstanced using the template and definition, here ShowDiscount.
2. Click on Save and select Specialize by circumstance.
3. Setting a Circumstance Template and a Circumstance Definition is required for the Circumstance by Template option (i.e. multivariate).
4. Modify the rule as desired to display to Indian Premium customers. Let us give them a 20% discount on all purchases.
5. Save and run the case. Select the category as Premium and Country India this time.
6. On submitting the section, the customer will be displayed with the newly circumstanced section instead of the base rule.
Time-varied circumstancing allow specializing a rule that based on a start date and/or an end date. At run time, the circumstanced rule is selected if the actual system time is after the start date and before the end date.
Three properties are involved here - Date property, Start Date and End Date
Based on the values set to these properties the rule gets picked by rule resolution.
Time varied circumstancing can be used to provide seasonal discounts in our example scenario.