Create Simple Rule Flow

This tutorial will walk you through the creation of a Rule Flow.

How to create a simple decision tree

Let's advance one step at a time.

In this tutorial, you need to have knowledge of Decision Tables or Scripting Rules.

1. Create Decision Tables

We have already learned how to create rules in previous tutorials, so let's skip it now and import these decision tables:

  • Clients - a rule that determines the maximum loan according to the client's age and salary

  • Loan Type - a rule that determines the maximum loan tax according to how much and for what the client wants to borrow

  • Bank Solver - a rule that calculates how much the client pays in total

How to import Decision Tables

2. Go to Create rule

3. Create a new Rule Flow

You will be prompted to provide a name and choose between SAMPLE RULE or EMPTY RULE. The new rule will be created and its detail will be displayed. We will continue in the Rule Settings tab.

In our case, we recommend you select the empty rule.

4. Set Rule Flow settings

When you click on RULE SETTINGS on the top left corner, the scripting rule's detail will appear first to set some information. We will change the name of our script. To do this, click on it's name, enter one you like and press Enter.

Since we do not want this rule to be available yet, we will change its status to "Pending". To do this, click on the current status "Published" and then select "Pending".

5. Create an Input and Output model

We will now create an input and output model, which will then be used to set conditions and results. You must be in Rule Flow Settings. There are 2 ways to create these models:

  • Simple editor: It is intended for inexperienced users who do not know the syntax of JSON files.

  • JSON editor: It is intended for an experienced user, with JSON knowledge.

Create with a simple editor

Input model

First, we delete all created objects by clicking on the icon (in case you chose Sample Rule Flow). Then we will add our specified requirements (age, salary, loan, loanType). In our case, we create a root for each request by clicking on the button.

If our model were more complex, we would add descendants. More information is described here.

Input model Example:

Output model

We set the output model similarly, where we set as root loan, tax, totalPay and message.

Output model Example:

Create using JSON editor

Input model

First, we will create one object into which we will put other objects with our requirements. We will create one empty object for each request.

Our model is simple, these objects do not contain any others (embedded attributes). For more complex models, more information is here.

Input model Example:

  "age": {},
  "salary": {},
  "loanType": {},
  "loan": {}

Output model

We set the output model similarly, where we set as root loan, tax, totalPay and message.

Output model Example:

  "loan": {},
  "tax": {},
  "totalPay": {},
  "message": {}

6. Creating Rule Flow schema

  1. Connect rules together and to input box and output box. In this case, the correct connect is as follows:

The rule should look as in the picture above.

7. Map data

To know, which data has to go where we have to map the data.

The example Rule Flow - Clients and Loan type works with user input data and subsequently, Bank solver works with input of user data and with outputs from previous rules makes the decision and sends final outputs to the output box.

7.1 Data mapping Clients

Global variable means where the rule takes data from and output means what data. Because this rule is connected immediately after the input box, only user input data can enter it.

Correct mapping of Clients from example:

7.2 Data mapping Loan type

The loan type is also directly connected after the input box, so only input user data will also enter it.

Correct mapping of Loan type from example:

7.3 Data mapping Bank solver

The bank solver is the final rule, that takes data from both the previous rules and the input box.

Correct mapping of Bank solver from example:

7.4 Data mapping Output box

The final output can be data from any rule, so it is necessary to map the Output as well. In this example we want the following data to be in the output:

  • Loan - the amount the customer wants to borrow

  • Tax - tax of the loan

  • TotalPay - the amount the customer pays

  • Message - that confirming the loan or explaining its refusal

Correct mapping for output:

8. Test of created Rule Flow

Now we can test our Rule Flow in Test Bench. Before testing the rule, we must change the status of the decision table to "Published" or have to debug mode ON. Debug mode allows you to test Rule Flow even when it is pending and at the same time writes data information to the debug mode console.

Now you can test your Rule Flow as you like, but for a positive result, it is necessary to have loanType set on "household", "car" or "vacation" because our bank does not lend to anything else.

You can add new loanType variables in the Loan Type rule via Preset values.

You can find more information about input and result at Solver API.

Request body example:

  "age": 30,
  "salary": 4000,
  "loanType": "household",
  "loan": 30000

Response body example:

    "loan": 30000,
    "tax": 1.15,
    "totalPay": 34500,
    "message": "eligible for the loan"

More information about Test Bench is here.

Last updated