Now, 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 their cumulativeCashBack account to reduce their total amount at checkout time.

Assuming that at the checkout time, the cashier asks the shopper if they want to apply their cumulativeCashBack amount to the current purchase’s totalAmount:
  • If the shopper says Yes, the shopping cart’s useCashBack attribute is true.
  • If the shopper says No, the attribute is false.

If useCashBack is true, you deduct cumulativeCashBack from the totalAmount, reducing the amount the shopper pays.

Finally, when a shopper applies their cumulativeCashBack balance, you reset the balance to 0.

You 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, you need only a few aliases to represent these perspectives of the Vocabulary. Define the rule scope as shown:



Add the third Rulesheet to the Ruleflow

With the creation of the third Rulesheet, you can complete this Ruleflow, implementing the execution sequence of the three 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, you had defined a Filter to filter out customers who are not preferred account holders. You define the same filter in the use_cashBack.ers Rulesheet, because only preferred customers are eligible for cash back and bonus incentives. You have defined this 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:



  1. Process the currentCart when the shopper has chosen to apply their cashBack balance to the current purchase, in other words, when useCashBack = true.
  2. Define an action to deduct the cumulativeCashBack from the totalAmount.

  3. To 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.
  4. Define the input as shown:

    Note: For this test, manually enter $9.24 in the preferred customer’s cumulativeCashBack attribute and indicate that they want to apply this balance towards today’s totalAmount (useCashBack = true).
    Note: According to the first rule in the use_cashBack.ers Rulesheet, the cumulativeCashBack should first be incremented by the new cashBack earned by today’s purchase, and then subtracted from the totalAmount to arrive at the final bill.
  5. Run the test.


The 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). You also see the cashBackEarned and the cumulativeCashBack values embedded in a rule message from the previous Rulesheet.

Now, model the second business rule:


  1. Ensure that the preferred customer is aware of their savings today.
  2. Assign the value of cumulativeCashBack to the attribute named savings.
  3. Assume that this savings value is shared with the customer on the receipt or in some other way. Then, you can reset the cumulativeCashBack value to 0.
  4. Define the actions and add a rule statement as shown:


    The rule is now complete. Here is the third and final completed Rulesheet.


  5. Test it using the same Ruletest, without modifying or adding additional input. Execute use_cashBack.ert again.


cumulativeCashBack is now 0, and savings has the value previously held by cumulativeCashBack. There is also a new rule message explaining what has happened. Your final rule works as expected.

Since this was a cumulative test, you can also be assured that the entire Ruleflow (all three Rulesheets) works as expected. The business problem has now been fully modeled and tested.

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 reveals incompleteness in each of the three Rulesheets. Identifying and resolving incompleteness or conflicts in these rules is left to you.