Skip to main content

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:

Decision table template

EmptyTemplateWithNumbers.png

Fields 1-5 are prefilled, fields 6-16 need to be filled in with the parameters/code described below.

  1. Name of the decision table

    Simple Contact Decision Table
  2. Packages that are being imported

    fi.fasolutions.mod.portfoliomanagement.domain.*,org.apache.commons.math.util.MathUtils,org.apache.commons.lang.StringUtils
  3. States whether code should be read sequentially or not

    TRUE
  4. States if loops should be allowed or not

    FALSE
  5. States the variables to be included:

    fi.fasolutions.mod.portfoliomanagement.service.Services services
  6. 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
  7. The first condition to be applied:

    status == "$1"
  8. The second condition to be applied:

    hasNotTag("$1")
  9. The action to be executed if the conditions are true:

    $c.setTag("$1")
  10. A short description of the first condition

    Contact status must be active
  11. A short description of the second condition

    Contact can not have tag "ActiveContact"
  12. A short description of the action

    Set tag "ActiveContact" on contact if conditions are true
  13. A unique description of a rule per row:

    Set tag "ActiveContact" if contact status is active and if the tag is not already set
  14. The value that "$1" is referring to in the first condition:

    A
  15. The value that "$1" is referring to in the second condition:

    ActiveContact
  16. 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:

custom_contact_setTagByStatus.xlsx

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:

  1. Add the ActiveContact tag to the contact tags in FA Back. See Preference - Tagsin FA Back reference for more details about adding tags.

  2. Click New > New contact to create a contact and choose Active in the Status field.

  3. 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:

2555805797.png