Model the third Rulesheet
- Last Updated: March 24, 2022
- 5 minute read
- Corticon
- Version 6.3
- Tutorials
We are now ready to model the last Rulesheet. Recall that the third Rulesheet corresponds to the third substep in the Checkout process.
One of the rules in the previous Rulesheet calculated a preferred card member’s cashBackEarned for each purchase and incremented the member’s cumulativeCashBack amount.
Now, let’s give the shopper the option of using the money in his cumulativeCashBack account to reduce his total amount at checkout time.
We’ll assume that at time of checkout, the cashier asks the shopper if he wants to apply his cumulativeCashBack amount to the current purchase’s totalAmount. If the shopper says “Yes” to using cash back, then we assume the shopping cart’s useCashBack attribute is true. If the shopper answers “No” then the attribute is false.
If useCashBack is true, then we will deduct cumulativeCashBack from the totalAmount, reducing the amount the shopper pays.
Finally, when a shopper applies his cumulativeCashBack balance, we reset the balance to zero.
We’ll model this as a single rule in Corticon Studio with one condition—check if useCashBack is true—and two actions—deduct cumulativeCashBack from totalAmount and set cumulativeCashBack to 0.
Create the Rulesheet
Let’s begin by creating a Rulesheet. Name it use_cashBack. Ensure that it uses the groceryStore.ecore Vocabulary.
Define the rule scope
Because the rules in this Rulesheet deal with a preferred shopper’s cart, we only need a few aliases to represent these perspectives of our Vocabulary. Define the rule scope as shown.
![]()
Add the third Rulesheet to the Ruleflow
With the creation of the third Rulesheet, we can complete our Ruleflow, implementing the execution sequence of the 3 Rulesheets. Open MyAdvancedTutorial.erf (if it isn’t already open), and add the use_cashBack.ers Rulesheet as shown.
![]()
Define a Filter in the use_cashBack Rulesheet
In the coupons.ers Rulesheet we defined a Filter to filter out customers who are not preferred account holders. We need to define the same filter in the use_cashBack.ers Rulesheet, since only preferred customers are eligible for cash back and bonus incentives. We need to define the Filter again because data that is filtered out in one Rulesheet is not automatically filtered out in other Rulesheets.
Define a Filter expression as shown.
![]()
Define a rule to apply cash back
Let’s start modeling the first business rule:
The rule has only one condition—check if the customer wants to apply their cumulativeCashBack to the totalAmount of the ShoppingCart. Define the condition expression as shown.
![]()
As you can see, we only want to process the currentCart when the shopper has chosen to apply their cashBack balance to the current purchase, in other words, when useCashBack = true.
Next, define an action to deduct the cumulativeCashBack from the totalAmount.
![]()
In keeping with our model/test approach, we’ll test the rule before adding more to it.
Create a Ruletest named use_cashBack.ert that uses the MyAdvancedTutorial.erf Ruleflow as its test subject. Define the input as shown.
![]()
For this test, we have manually entered $9.24 in the preferred customer’s cumulativeCashBack attribute and indicated that they want to apply this balance towards today’s totalAmount (useCashBack = true).
According to our first rule in the use_cashBack.ers Rulesheet, the cumulativeCashBack should first be incremented by the new cashBack earned by today’s purchase, then subtracted from the totalAmount to arrive at the final price.
Run the test.
Our rule has worked as expected. The Output panel shows the new cashBackEarned ($1.64) is added to cumulativeCashBack ($9.24+$1.64=$10.88) and subtracted from totalAmount ($82.49-$10.88=$71.6). We also see the cashBackEarned and the cumulativeCashBack values embedded in a rule message from the previous Rulesheet.
But we’re not done. We still need to model the second business rule:
We need to reset the cumulativeCashBack attribute to 0. Before do this, we want to ensure that our preferred customer is aware of their savings today. Let’s assign the value of cumulativeCashBack to the attribute named savings. We’ll assume that this savings value will be shared with the customer on the receipt or in some other way. Then, we can reset the cumulativeCashBack value to 0.
Define the actions and add a rule statement as shown.
The rule is now complete. Let’s test it using the same Ruletest. You do not need to modify or add additional input. Execute use_cashBack.ert again.
As you can see, cumulativeCashBack is now 0, and savings has the value previously held by cumulativeCashBack. There is also a new rule message explaining what has happened. Our final rule works as expected.
Since this was a cumulative test, we can also be assured that the entire Ruleflow (all 3 Rulesheets) works as expected. The business problem has now been fully modeled and tested.
Here is our third and final completed Rulesheet.
A note about logical validation
While these Rulesheets successfully model the scenario’s business rules, they are not “complete” from a logical standpoint. Corticon Studio’s completeness check will reveal incompleteness in each of the 3 Rulesheets. Identifying and resolving incompleteness or conflicts in these rules is left to you.