Create a Simple Decision Table
This tutorial will walk you through the creation of a simple Decision Table.
Last updated
This tutorial will walk you through the creation of a simple Decision Table.
Last updated
Decision Tables are without a question one of the most important tools for creating business rules. Within DecisionRules, they are fairly easy to create and manage. We believe that, with the help of this tutorial, you can master the basics quickly.
Let's advance one step at a time.
Becoming a superhero is a fairly straightforward process. After entering our login page, you will be able to pass your credentials and log in.
There are multiple options for user login. If you do not have an account yet, you can create one. After logging in to the application, the Dashboard will be displayed.
You will be prompted to provide a name and choose between SAMPLE RULE or EMPTY RULE. For now, name the rule as you wish and choose the EMPTY RULE. The new rule will be created and its detail will be displayed. We will continue in the Rule Settings tab.
More information can be found in our documentation on Decision Tables.
Once we are in the Rule Settings, let's do some settings. Since we do not want this decision table to be available yet, we will change its status to Pending. To do this, click on the current status Published and then select Pending.
We will now create the input and output model which is used to set conditions and results. There are 2 ways to create these models:
Simple editor is intended for inexperienced users who do not know the syntax of JSON files.
JSON editor is intended for an experienced user.
Let's start with the input model. First we delete all default attributes by clicking the trash can icon. Then we add our own attributes: period
, productType
and promoCode. We create a root for each of them by clicking the +Add root button.
More information on the simple editor is provided here.
Now we can continue with the output model. It will be set similarly. As root attributes, we add pricesand message. Here, we would like to add a child attributes to the . We do that by clicking the + icon within the prices field. We rename the New Attribute to finalPrice and then add one more, crudePrice.
In the JSON editor, we can provide the input and output model in JSON format. In our case, the input model will read
while the output model shall read
For now, you may just enter these values and you are done!
More information on the JSON editor can be found here.
To create conditions and results, you must go to the Table Designer tab. Now let's move on and bind our input and output models to our condition and result columns.
We already have one condition column and one result column here. We start with the conditions. Click the input dropdown and select productType. Then click the + button at the top of the conditions section twice to create two more columns. Bound these to our period and promoCode input attributes. These are all the conditions we will use.
Next we add the result columns. One is already there, so click the output dropdown and select prices.crudePrice. Then create two more columns by clicking the + button at the top and bind them to prices.finalPrice and message. These are all the results we need.
More information about creating conditions and results can be found in the Table Designer Section and Binding to Model Section.
After adding conditions and results, we can also set their names. To do this, click the name, currently reading New Condition, and rewrite it.
Currently, we have a single row in the Decision Table.
Each row of the table corresponds to one set of conditions and results. When the Rule Solver is called, it goes through the individual rows and evaluates their condition values against the corresponding request input data. If some values of the conditions in a row match, Rule Solver takes the values of the individual results on that row and places them in the output.
Let's set the conditions in the first row.
Click the anything label in the productType column. You can choose a type of condition from the Select type modal. We would like to activate the results of this row when the value of productType is basic
. We can do that simply by selecting the Equals operator and entering the string basic
.
We will use the Equals operator for period as well. This row will activate when the period will be equal to month
.
Here we want to check whether the customer's promo code is correct. We could again enter the desired value with an Equal operator, but we can do better. Let's go to Rule settings and open the Rule Variables section. Here we shall add two Rule Variables. The first one will have name PromoCode
and value SUMMER SALE
while the other will have name PromoDiscount
and value 30
. Rule variables make our rules easily manageable. If we later want to change the promo code, we do it only on a single place: in the Rule Settings.
Click Save and go back to the Decision Table Designer. Now you can add the condition for promoCode. Select again the Equals operator and eneter {PromoCode}
in the field. This expression refers to the PromoCode
Rule variable.
Now we are going to continue with setting results.
In the prices.crudePrice column, leave the simple value denoted by = and enter 8
. This is the crude price for our service in case of basic subscription for a month.
Because we are in the row where the promo code is matched, we will give a discount on the crude price. Click the = sign and select Function. Then enter the following expression:
It means that we calculate the final price by taking the crude price and subtracting 30% discount defined by the PromoDiscount
variable. Note that we are referring to the prices.crudePrice column by writing {prices.crudePrice}
.
Finally, let's include some message about what happened on this row. In the message column, again select the Function type of the result and enter the following expression:
This function will take the PromoDiscount
variable and concatenate it with the given string to generate the desired message.
You can now click the three dots at the beginning of the row and select Insert Below. This will add another empty row below. Its conditions and results may be set analogically. More rows can be added in a similar fashion. In this way, you can create a rule similar to the following sample rule.
You can import this rule to your space by going to Decision Tables and clicking the Import button.
Now we can test our rule in Test Bench. Before testing the rule, we must go to Rule Settings and change the status of the decision table to Published.
For example, if we switch to the JSON Bench, we may input the following data.
Upon hitting Run, we will get the following response.
More information about Test Bench can be found here.
If you have arrived here, you have successfully completed the tutorial. Congratulations!
To display the rule creation pop-up click the button on the sidebar.
To apply these changes, we have to click the button at the bottom of the page.
After creating an input or output model, we must always confirm the changes with the button.
Do not forget to click thebutton.
Do not forget to click thebutton.
If we want to test a certain row, we can click the icon at its beginning. After clicking the icon, the values from the row will be pre-filled in Test Bench, which will show up at the bottom of the page. We can freely modify these values. For instance, if you click the first row of your Decision Table, you will have to enter the correct promoCode, which should be SUMMER SALE
.
Then we can click the button and the result will be displayed in right hand side of the Test Bench. Note that you can switch between the Simple Bench and the JSON Bench.