Rule Chains
  • 10 Aug 2021
  • 4 Minutes to read
  • Dark
    Light
  This documentation version is deprecated, please click here for the latest version.

Rule Chains

  • Dark
    Light

Article summary

Overview

Rule chains are a set of rules combined together in sequence, where every rule produces a fact that is both an output of the rule chain and can be consumed in rules further down the chain. Rule chains can be used to build dynamic questionnaires, evaluate a specific rate, or generate an output for wherever business processes require dynamic decision-making.


Defining Data for the Rule Chain

Before a Rule Chain can be created, it needs some data to evaluate. There are two ways to get outside data into the Rule Chain:

  • Define input data to be mapped into the Rule Chain
  • Define constant data that will only be used within the Rule Chain.


Example 

This example will demonstrate how to create a Rule Chain that contains a Rule to evaluate if a string contains "@decisions.com".

  1. In a Designer Project, click CREATE FLOW. Select the Flow category, select Default, and click CREATE. 
  2. Click the Done path on the Start step. Navigate to Flows, Rules, Forms and Reports > Rules and select Run Rule Chain.
  3. Under the Chain Settings category on the Properties panel, click Create.
  4. Name the Flow and click CREATE.
  5. On the Steps panel, expand Rule Chaining [DMN]. Click and drag the Input Data step to the workspace.
    Input Data steps allow for the custom definition of the data members needed as inputs for the Rules in the chain. Add one or more inputs to each input step. Input Data steps can also have unlimited paths coming in and out of them.
    Business Knowledge and Knowledge Source steps. The Business Knowledge and Knowledge Source steps allow for the creation of constant data within the Rule Chain. The declared data is passed into all connected steps as available input data. No mapping outside of the Rule Chain is required.


  6. Under the Data Definitions category, select Show Editor
  7. Enter "Input 1" in the Name field and select String [Text] as the Type. Click CLOSE to save and close the window.


    Defining the inputs will expose input variables on the Rule Chain, similar to a Start step in a Flow. To use a Rule Chain in a Flow, these configurations will get data from the Flow into the Rule Chain. When data is not supplied to an input all steps connected to a null Input Data step do not execute. This is because Input Data steps create a dependency on all connected steps. The Rule chain will also output a list of Not SUpplied Inputs as DataDescription[]. This list can be used Rule Chain to determine why certain facts were not produced by the Rule Chain.


  8. On the Steps panel, select and drag a Statement Rule [Decisions] to the workspace.
  9. Hover over the Input Data step and drag the line to the Statement Rule step. With the Statement Rule step selected, click Edit under the Settings category.


    By design, data is automatically mapped into connected Rule steps. 


  10. Click Select Data Element. Select Input 1 and click NEXT.
  11. Select Contains under the Text Rules category and click NEXT.
  12. In the value field under the Inputs category, enter "@decisions.com" and click DONE.
  13. Click Add in the Result bracket and select New Output Data.
  14. Enter "Value" in the Name field and click OK.
  15. In the text field next to Value, enter "This string contains @decisions.com".
  16. Select the option Show Else Result under Output on the Properties panel. Click Save to save changes and click Close.


    By default, connected rules only execute if the rule produces a result. To change this behavior, there is a setting to allow connected steps to also execute when the rule returns no result.


  17. On the Rule Chain Flow diagram, click Save and click Close.
  18. On the Rule Chain Step, enter "test@decisions.com" for Input 1. Connect the Done step to the End step. Click Save.


    When the Rule Chain is called in a Flow as a step, the result data of the rules are output by the entire Rule Chain step. These are referred to as the Facts that the Rule Chain step is able to produce.  By default, all Facts are checked and the Rule Chain will attempt to collect them all. In other words, when the Rule Chain executes it goes down every path. This is known as forward chaining. Alternatively, Facts can be deselected on the Rule Chain step. This means the paths that were required to gather these Facts are no longer executed. This is known as Backward Chaining.


Adding Flow Controls to a Rule Chain

Flow Control steps in a Rule Chain help route which paths execute in the chain. They do not return data or produce 'Facts'.


Should Continue step

The Should Continue step helps to create a typical If/Then Statement Rule. The step can have unlimited paths coming in and out of it. If the rule evaluates true, then all paths coming out of the Should Continue step will execute. Alternatively, if the rule evaluates false paths coming out of the Should Continue step no longer execute.

True-False Rule step

The True-False Rule step also allows for the creation of an If/Then Statement Rule that does not return data. The step can have unlimited paths coming in, but only a True and False path is available coming out of the step. If the rule evaluates true, only the true path is taken. If the rule evaluates false, only the false path is taken.


Debug

  1. Select Debug on the top action bar and click FULL.
  2. After the debugger runs, select the Rule Chain Flow Step 1 Rule to see that the value evaluated to True.


Was this article helpful?