What's a technical rule?

Are generally not created in this web UI:
  • Developer teams author technical rules
  • Then uploaded to the repository
  • Appear here in a free form editor
  • No syntax help in editor (caution...)
  • Business users advised to stick with guided rule editors
  • For developer completeness, let's code a technical rule...

Total Shopping Cart Items - Create technical rule

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

Total Shopping Cart Items - The editor

Presented with the free text editor for our rule (DRL). Note this package line shown highlighted here is providing access to all of our data objects:

Total Shopping Cart Items - Technical rule outline

Add basic rule outline, noting indentation:
  • rule "Total Shopping Cart Items"
  • ruleflow-group "pricing-rules"
  • no-loop true, when, then, end

Total Shopping Cart Items - The WHEN section

Now lets look at the conditions (WHEN), cut and paste into editor:
  • A ShoppingCart assigned variable: $sc
  • $sc : ShoppingCart()
  • A ShoppingCartItem assigned variable: $sci
  • The ShoppingCartItem is in the shopping cart: $sci
  • $sci : ShoppingCartItem( shoppingCart == $sc )

Total Shopping Cart Items - The THEN section

The rule applies four actions (THEN) if fired, cut and past into editor:
  • Modify value of shopping cart cartItemTotal
  • $sc.setCartItemTotal( $sc.getCartItemTotal() + ($sci.getPrice() * $sci.getQuantity()));
  • Modify value of cartItemPromoSavings
  • $sc.setCartItemPromoSavings($sc.getCartItemPromoSavings() + ($sci.getPromoSavings() * $sci.getQuantity()));
  • update ShoppingCart: update( $sc );
  • retract ShoppingCartItem: retract( $sci );

Total Shopping Cart Items - Verify rule

This completes the technical rule, it 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 Total Shopping Cart Item technical 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 7 - Create guided decision table