Create, deploy and verify a decision table
Overview
This tutorial provides instructions for how to create a decision table, deploy it in FA Back and verify that it works as intended. The decision table checks if the contact status is active and sets the tag "ActiveContact" if the condition is true. It also checks if the tag already is set, if it already exists no tag is set.
Step 1 - Create a decision table
Download the Excel template:
Fields 1-5 are prefilled, fields 6-16 need to be filled in with the parameters/code described below.
Name of the decision table
Simple Contact Decision Table
Packages that are being imported
fi.fasolutions.mod.portfoliomanagement.domain.*,org.apache.commons.math.util.MathUtils,org.apache.commons.lang.StringUtils
States whether code should be read sequentially or not
TRUE
States if loops should be allowed or not
FALSE
States the variables to be included:
fi.fasolutions.mod.portfoliomanagement.service.Services services
States the object that the decision table should be applied to (contacts, portfolios, securities, transactions etc). Note: The object must stretch over all condition columns.
$c:Contact
The first condition to be applied:
status == "$1"
The second condition to be applied:
hasNotTag("$1")
The action to be executed if the conditions are true:
$c.setTag("$1")
A short description of the first condition
Contact status must be active
A short description of the second condition
Contact can not have tag "ActiveContact"
A short description of the action
Set tag "ActiveContact" on contact if conditions are true
A unique description of a rule per row:
Set tag "ActiveContact" if contact status is active and if the tag is not already set
The value that "$1" is referring to in the first condition:
A
The value that "$1" is referring to in the second condition:
ActiveContact
The value that "$1" is referring to in the action:
ActiveContact
Now you can save the decision table. You can also download the final version of the decision table here:
Step 2 - Deploy the decision table in FA Back
In FA Back, go to Tools → Administer → Decision tables and upload the decision table.
Click Preview all. The decision table is evaluated and converted to Drools code that appears in the box to the right.
You have now deployed a decision table that is ready to be verified. Click Done to validate and take into use your decision tables. If there are issues with the syntax, you will be notified and the window remains open. The errors can also be seen in the box on the right. Once any issues are solved, click Done again to close the window.
Step 3 - Verify that the decision table works correctly
To verify that the decision table works correctly:
Add the ActiveContact tag to the contact tags in FA Back. See Preference - Tagsin FA Back reference for more details about adding tags.
Click New > New contact to create a contact and choose Active in the Status field.
Click Save and verify that the ActiveContact tag is set.
You have now verified the decision table and it is ready to use.
Troubleshooting
Object modification done in the action is not reflected and visible in the next rule that is run
Modifications done in the rule action is not by default visible to other rules that runs after the current one. If you want this behavior, you need to explicitly tell the rule engine to expose the change by adding update to the last action run in the rule.
update($t)
For example:
$t.setTag("$1");$t.setTags($t.getTags());update($t);
Note that unless you define "no-loop equals true" in the ruleset or in the rule level, also the rule in question is run again.
Rule conditions and actions are mixed
Conditions are accompanied by an object for which the rule is run, while actions are not. Therefore when defining the rule, make sure the $c:Contact, $p:Portfolio, $s:Security or $t:Transaction is only under the condition columns. Actions should not have related objects.
Example: