Create your First Project

◷ Reading Time: 18 minutes

Create a New Project

Open FlexRule Designer.

Sign in using your FlexRule username (not email) and password.

Once you log in successfully, it will open the home page.

Click on Create a New Project.

Enter a name and project path to save the project and click OK.

The project will then be created as shown below.

Download the help content if you see the notification.

Create the Concept

Add documents to the project.

Select Fact Concept and add it.

Drag and drop a Fact.

Double-click on the fact name and change it to ‘Person’.

Right-click on the fact, and select Edit Members.

Add the member ‘Age’. Its Type should be Integer.

Add another member for ‘State’. But this time, we are not adding any Type.

Drag and drop an Option.

Double-click and rename it to ‘State’.

Right-click on the ‘State’ option and add members.

Drag the cursor from State() in Person fact, to State option to connect them.

Add another member ‘IsMember’ and the Type should be boolean.

Validate the concept document.

There should be no errors in the document. If you see any errors, you should fix them before moving on.

Save the concept document.

Create a Decision Table

Add new file.

Add a decision table and name it ‘Store Discount.xml’.

Double-click on the created decision table to open it.

Click on Variable Parameters to add parameters.

From Assembly, select the concept document we created in the previous section.

Select the fact from Type.

Add a name to the concept.
As you can see below, the Direction of the variable should be In as we will input the person’s data.

Next, add a Local variable called ‘StoreDiscount’. This is what we use to assign the discount in this decision table. Its Type should be decimal.

Select the column and change the Column Name to ‘Age’.

Now click on Expression to add an Expression to the column. If you press Ctrl + Space, you will see the list of defined variables.

Select Person from the list.

When you type . it will show the members of the fact, ‘Person’. Select Age from that list.

Now we have added the column name and expression to the first condition.

Drag and drop another condition.

In the same way, we added ‘Age’, add column name, and expression for ‘State’.

Drag and drop an Action.

In the same way we added ‘Age’, add column name, and expression for ‘Store Discount’.

Type the following data to create the first rule.

Click New Row After to add a new row.

Enter the following rules.

[ and ] represent the inclusion. ( and ) represent exclusions. In this example, [50;65) means greater than or equal to 50 and less than 65.

Click on Properties to open document properties.

Select false from Process All Rows to make the decision table a single-hit. Then execution of the decision table stops as soon as a business rule is satisfied.

Now you will see that the decision table is a SingleHit.

Validate and Debug

First, we will validate it.

If there are any errors, you will see that in the Message List window.

Click on Debug with JSON Composer.

Click Yes to save the document.

Enter Age and State and click OK. For example, let’s enter 54 as Age and Select NSW from the drop-down list.

Execution will start and click Next Step to go step-by-step.

Keep clicking Next Step until you get a rule that gets satisfied. Since we made the decision table SingleHit, the execution completes as soon as a rule is satisfied. You can see the satisfied rule in Green.

If you look at the Parameters window, you can see the output StoreDiscount as 0.3

Create a Natural Language Document

Click on New.

Add Natural Language document as ‘Extra Discount.xml’.

Double-click and open the Natural Language document.

Click on Variable Parameters.

Add ‘Person’ and ‘ExtraDiscount’ variables.

Press Ctrl + Space to view the variables.

Select ‘Person’ and press . to see the list of members in ‘Person’. Select ‘IsMember’ from the list.

Complete the logic by adding the actions. You can always press Ctrl + Space to view the defined variables.

when a logic name
  Person.IsMember 
then
	ExtraDiscount = 0.3
otherwise
	ExtraDiscount = 0.1
end

Validate and Debug

Validate the document.

You can see the validation results.

Click Debug with JSON Composer.

Click Yes, if you haven’t saved the document already.

Select Yes and click OK.

Click Next Step until the execution completes.

You will see the matched business rule highlighted in Green.

You can see the results in the Parameters window.

Create the Decision Requirement Diagram (DRD)

Click on New.

Add a DRD. Let’s call it ‘Calculate Discount.xml’.

Double-click on the file to open it.

Drag and drop the logic files: Store Discount.xml and Extra Discount.xml.

You can resize the node.
To resize the label, press Alt and click on the label.

Drag and drop a Decision node from the toolbox.

Rename the node to ‘Calculate Discount’.

Add an Out variable called ‘Discount’.

Click on the node ‘Calculate Discount’ and add the following expression to it.

Discount = StoreDiscount + ExtraDiscount

Connect the nodes defining the decision hierarchy.
You can see that to calculate the discount, you need both store and extra discount.

Drag and drop an Input Data node.

Change its properties. So, the input will be the Person object defined in the concept file.

Connect it to the main decision which is ‘Calculate Discount’.

You can change the colors to make the final decision clear.

Validate and Debug

Validate the document.

There should be no errors.

Debug the document.

Enter the test values and click OK.

Click Next Step at every step.

Click Yes to go into the child model.

You can see the output which is the calculated ‘Discount’ in the parameters window.

Create a Logic Run Template

You can create a Logic Run Template to store input data. Then, instead of manually entering input values, you can select a template and debug/ run it.

Open the file Calculate Discount.xml.

Click on Debug with JSON Composer.

Enter the values you want to test.

Click Save as Run Template.

Give a title and description.

The Logic Run Template is saved.

You can close the Input JSON Composer.

Now if you click on Logic Run Template, you will be able to see the saved template.

You can debug or run the selected template.

Updated on March 31, 2021

Article Attachments

Was this article helpful?

Related Articles