Creating standard guided rules

In the previous lab 4 you created a guided rule using your DSL. Now let's create a guided rule without using a DSL. To add a guided rule, first have to return to Asset view. Click on retail-webshop project in bread crumb menu at top:

Total Shopping Cart - Create guided rule

Click on ADD ASSET -> GUIDED RULE to open pop-up, create 'Total Shopping Cart' rule, and click on +OK to create rule:

Total Shopping Cart - The editor

The guided rule editor is now open before you, note the green `+` signs on the right, these open lists of options:

Let's check the data objects first, switch tabs by clicking on Data Objects tab

Total Shopping Cart - Rule data objects

This view is of the available date model objects for use in this guided rule. Ensure each data object (4x) is added as shown with +NEW ITEM:

To import data objects outside the same package as this rule, you can use +New Item to import (not needed for lab)

Total Shopping Cart - The WHEN section

Return to Model tab and start designing guided rule. Top green `+` is for the WHEN (condition) section of our rule. Click on this top green `+` to open pop-up:

Total Shopping Cart - Add a ShoppingCart

The condition (WHEN) need is:
  • There is a 'ShoppingCart'

Select ShoppingCart from menu and click on +OK:

Total Shopping Cart - Assign ShoppingCart variable

The condition has now been added to the WHEN section:

To assign variable name '$sc' click on ShoppingCart for pop-up and fill in Variable name as shown and click on Set button:

Saving your work

  • Be sure to SAVE your work by clicking button top right
  • Optionally add a comment and click SAVE WITH COMMENTS drop-down in menu
  • This completes the WHEN section of your rule

Total Shopping Cart - First THEN action

The action (THEN) is a two part action. Click on bottom green '+' on right for pop-up, We want to modify value of ShoppingCart ($sc):
  • in pop-up, select Modify $sc... and click +OK to add

Total Shopping Cart - Add field cartTotal

Now add a field cartTotal in THEN section by clicking on pencil icon and selecting field cartTotal in pop-up to add:

Total Shopping Cart - Add value to cartTotal

Now assign value 0.0 to cartTotal by clicking on pencil icon next to cartTotal, select Literal value:

Total Shopping Cart - Second THEN action

Can you complete the second action (THEN) yourself? Modify value of ShoppingCart field cartItemPromoSavings to the following formula (hint: use formula instead of literal value):
  • ($sc.cartItemPromoSavings == 0.0) ? 0.0 : $sc.cartItemPromoSavings * -1

Total Shopping Cart - Set options

Expand the 'show options' and add attributes, use green '+' on right:
  • check NO-LOOP box
  • RULEFLOW-GROUP: total-rules

Saving your work

  • Be sure to SAVE your work by clicking button top right
  • Optionally add a comment and click SAVE WITH COMMENTS drop-down in menu
  • This completes the Total Shopping Cart rule

Returning to Asset view

To add our first guided rule, first we have to return to Asset view by clicking on retail-webshop project in bread crumb menu at top. (Returning to Asset view can be done at any time)

Apply Cart Item Promotions - Create guided rule

Click on ADD ASSET -> GUIDED RULE to open pop-up, create 'Apply Cart Item Promotions' rule, and click on +OK to create rule:

Apply Cart Item Promotions - Rule overview

The condition (WHEN) is two fold:
  • Part I is about a ShoppingCartItem
  • Part II is about a PromoEvent that monitors an event stream 'Promo Stream'

The action (THEN) will modify two ShoppingCart fields:
  • promoSavings field
  • price field

Switch tabs by clicking on Data Objects tab

Apply Cart Item Promotions - Rule data objects

Ensure that data model (4x) added in Data Objects tab:

Return to the Model tab to start on the guided rule

Apply Cart Item Promotions - WHEN part 1

The condition (WHEN) Part I:
  • 'There is a ShoppingCartItem'
  • Assign a variable name to this ShoppingCart '$sci'
  • Add a restriction on field 'itemID'
  • Assign by clicking, variable name to itemID: '$itemID'

Apply Cart Item Promotions - WHEN part 2

The condition (WHEN) Part II:
  • Use top green + to add second condition
  • Start with from Entry Point and fill in: 'Promo Stream'

Apply Cart Item Promotions - WHEN part 2 (continued)

The condition (WHEN) Part II (continued):
  • Within condition click on red '(click to add patterns...)'
  • Add PromoEvent, results in 'There is a PromoEvent'

Apply Cart Item Promotions - Multiple field constraint

Next, clicking on `There is a PromoEvent` for a pop-up, select from drop down menu for multiple field constraint:
  • All of (And)
  • Results in 'with all of the following'

Apply Cart Item Promotions - Field itemId restriction

Next, click on 'all of the following' line to add:
  • Add a restriction on a field, select itemId
  • Now use drop down menu to set it 'equal to'

Apply Cart Item Promotions - Setting bound variable

Next, click on the pencil icon for pop-up:
  • Click on the Advanced options: Bound variable
  • Select $itemID from the inserted list

Apply Cart Item Promotions - Field percentOff restriction

To wrap up the condition (WHEN), click on 'all of the following' line to add:
  • Add a restriction on a field, select percentOff
  • Click on percentOff and bind field to variable: '$pctOff'
  • percentageOff is over sliding window: 'none'

Apply Cart Item Promotions - Verify WHEN section

The conditions (WHEN) are finished, verify that yours looks like this:

Saving your work

  • Be sure to SAVE your work by clicking button top right
  • Optionally add a comment and click SAVE WITH COMMENTS drop-down in menu
  • This completes the Apply Cart Item Promotions WHEN section

Apply Cart Item Promotions - Complete the THEN section

The actions (THEN) part of our rule is next, add the following using bottom green `+`:
  • Add: 'Modify value of ShoppingCartItem ($sci)'
  • Use pencil icon adding: 'promoSavings is set to 0.0'
  • Add second: 'Modify value of ShoppingCartItem ($sci)'
  • Use pencil icon adding: 'price is set to 0.0'

Apply Cart Item Promotions - Set options

Expand the 'show options' and add:
  • check NO-LOOP box
  • RULEFLOW-GROUP: promo-cart-rules

Apply Cart Item Promotions - Verify rule

This completes the guided rule, should look like this:

Saving your work

  • Be sure to SAVE your work by clicking button top right
  • Optionally add a comment and click SAVE WITH COMMENTS drop-down in menu
  • This completes the Apply Cart Item Promotions rule

Returning to Asset view

Finally, we return to Asset view by clicking on retail-webshop project in bread crumb menu at top. (Returning to Asset view can be done at any time):

Lab completed - Results

Eric D. Schabell
Portfolio Architect Director
@ericschabell
http://schabell.org
More Red Hat Decision Manager Workshops:

Red Hat Decision Manager Articles:

Red Hat Decision Manager Demos:

Up next...

Lab 6 - Create technical rules (DRL)