Decision Table Hello World

From FlexRule Wiki
Jump to: navigation, search


Bulbgraph.pngPlease ensure you have installed both FlexRule Runtime and FlexRule Designer on your machine. You can download the products from

Decision table is a tabular form to model business rules consists of

  • Conditions (input)
  • Actions (output)

And some other columns i.e. name, priority...

Info2.pngTo learn more about Decision Table in depth, please follow Introduction to Decision table section.


In this tutorial, we are going to create a simple Decision table that calculates the Delivery costs based on Total Weight of a parcel. In the post office usually this is based on couple of conditions and business rules. But for the sake of this tutorial, let's make it as simple as below business rules:

  1. If is Package between 0 and 22 kg then the delivery cost is 30$
  2. If is Package between 22 and 50 kg then the delivery cost is 33$
  3. If is Package between 50 and 110 kg then the delivery cost is 120$
  4. If is Package is heavier than 110 kg then the delivery cost is 200$

New Project

Let's create a new project. By going to Project->New menu and fill the below information:


And when you are asked to link the Runtime


Press "Yes" this will link the installed FlexRule Designer to the new project.

Bulbgraph.pngMake sure you have the FlexRule Runtime installed on your machine, before creating a new project.

Add new Decision Table

Let's add a new Decision table document by going to Document->New menu:


And change the name to Calculator.xml.

Once you created this new Decision table, then find the file in your Project Explorer and double click on it to open. Then you can see below screen in your FlexRule Designer:


Setting Parameters

To communicate to a logic document (i.e. decision table in this case) we need to define input and output parameters:

  1. Input: Total Weight
  2. Output: Delivery

Press on the Properties on the toolbar of Decision table:

Delivery Calculator-toolbar-properties.png

Then in the properties window find the Parameters Declaration and the Click on the Variable Definition button:

Delivery Calculator-DT-properties.png

And then add the below parameters:

  1. Input: Total Weight
  2. Output: Delivery

Delivery Calc - Parameters.png

Info2.png Learn more about Parameters and how to use them.

Entering Business Rules

Using the toolbox, drag and drop required conditions and actions.

Delivery Calculator-building-rules.png

In this tutorial, we need:

  1. two conditions
  2. one action

Once you added the conditions and action, then start setting property of Column Name for each column in the decision table:

  1. Select first column
  2. On the properties window, select Column Name
  3. Add the value for the column name
  4. do the same for all the columns
  5. Then add the business rules into your decision table

And build the below decision table:

Delivery-DT-with rules.png

Setting Expressions

Now the modeling is done, you need to bind each column to runtime. Which means you need to link each column to its Parameters. In below expressions $value refers to the value that is entered in each cell.

Minimum Weight

Build the below expression for Minimum Weight column:

Total Weight > $value

Follow the below instruction to set the expressions for each column:

Minimum Weight

Build the below expression for Minimum Weight column:

Total Weight > $value

Maximum Weight

Build the below expression for Maximum Weight column:

Total Weight <= $value

Setting Hit Policy

When any of the rules met the criteria and the delivery cost is decided, the execution must be finished. So we should set the Hit Policy of the decision table to SingleHit.

  1. Select the Properties button on the Decision Table toolbar
  2. In the Properties Window, find Process All Rows properties
  3. And set its value to false

As the result in the decision table model, you must see the hit policy is set to SingleHit


Save and Validate

Make sure your document (i.e. this decision table) is saved. (Project->Save menu). Then From the menu, select Document->Validate and you should see the below image as the result of validation:


This means your decision table is all good and no issue (error, overlap, missing...) could be found with it.

Providing Input Values

In FlexRule Designer you can simply provide values to your logic and check the results. To doing that you need to:

These steps allows you to build values and bind them to parameters of your logic.

Info2.pngLearn more about Data composer and Debugging to understand the concepts.

Running the Rules

At this stage, after providing the input values, your decision table goes into the Debug mode and you see the below screen:


You can use menu Debug->Next Step to run current selected (Yellow highlighted rule). And then the debugger goes to the next one. Keep doing that until you reach the rule #3 which meets the entered Total Weight of 60.60 condition Total Weight is between 50 and 110.

Bulbgraph.png Yellow highlight is the current rule, that is about to execute.


Bulbgraph.pngGreen highlight means the conditions of the rule are met and the action is executed.

Viewing Results

In your FlexRule Designer switch the bottom pane to Parameter Window and you can see the parameter values:


Integration into Application

To integrate into your application, please follow Integration instruction.