Drools Business Central

Create rules in Business Central

In this tutorial we will see how to setup/create a business rule. We will create required assets for the below business rule.

Rule: If holiday season is Diwali/New Year/Pongal, then apply 15% discount on Order.

To start, we would need to create a space in Business Central. After this we would create project under space. In the project, we would setup the rules. We have provided the step-by-step details below.’

1) Create Space

a) Login to Business central with default credentials (username: admin and password: admin).

b) After login, it will take you to the main screen.

c) Click on Design and then click on “Add Space “.

d) Enter name and description values and then click on ‘Add’ button.

  • Name field is mandatory (so we have entered the name as ’drools-space’).
  • Description field is optional.

e) Space has been created with name as ’drools-space’. Now we would create a project under ‘drools-space’ space.

2) Create Project

a) Go to ’drools-space’ space and click on ‘Add Project’.

b) Enter project name and description and then click on ‘Add’ button.

  • Name field is mandatory (we have entered the name as “orders”).
  • Description field is optional.

c) Project has been created with name as ‘orders’. Now we would create assets under ‘items’ project to setup rule.

3) Create Assets

a) Go to ‘orders’ project and click on ‘Add Asset’.

b) We need two assets to setup/create rule: 1) Data Object/model and 2) DRL File. We would create ‘Data Object’ first.

c) Click on ‘Data Object’ asset. Enter asset name (as Order), select package having your space & project name and click on ‘Ok’ button. It would create ‘Item.java’ data object.

d) Now add the required fields by clicking on ‘+ add field’ button in ‘Order.java’ data object.

Field NameType
productNameString
seasonString
discountDouble

e) Enter Id/field name (Mandatory), Label (Optional), and Type (Mandatory) for all the required fields one by one. Click on ‘Create and continue’ button to add next field.

f) Once you added all fields, click on ‘Save’ and then click on ‘Validate’ button to check for any errors.

g) Finally click X (close icon) and you will be redirected to Assets page which list your data object that you just created.

h) Click on ‘Add Asset’ again & select ‘DRL File’ asset type. Enter asset name (as OrderRule for our case), choose your package and click on ‘OK’ button.

It would create ‘OrderRule.drl’.

i) Add the following rules in OrderRule.drl

package com.drools_space.orders;

rule "Find discount based on season"
	dialect "mvel"
	when
		item : Item( season == "Diwali" || season == "New Year" || season == "Pongal" )
	then
		item.setDiscount( 15.0 );
end

j) Click Save to save your work and finally you get below.

k) Close (X) ‘OrderRule.drl’ guided rule file & you will be redirected to assets screen showing your 2 assets:

About the Author: Elavarasan PK

Technical Specialist, Intersoft Data Labs