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).
![](https://www.hitechpoints.com/wp-content/uploads/2023/06/image-12-1024x456.png)
b) After login, it will take you to the main screen.
![](https://www.hitechpoints.com/wp-content/uploads/2023/06/image-13-1024x428.png)
c) Click on Design and then click on “Add Space “.
![](https://www.hitechpoints.com/wp-content/uploads/2023/06/image-14-1024x276.png)
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.
![](https://www.hitechpoints.com/wp-content/uploads/2023/06/image-15-1024x372.png)
e) Space has been created with name as ’drools-space’. Now we would create a project under ‘drools-space’ space.
![](https://www.hitechpoints.com/wp-content/uploads/2023/06/image-16-1024x279.png)
2) Create Project
a) Go to ’drools-space’ space and click on ‘Add Project’.
![](https://www.hitechpoints.com/wp-content/uploads/2023/06/image-17-1024x423.png)
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.
![](https://www.hitechpoints.com/wp-content/uploads/2023/06/image-18-1024x422.png)
c) Project has been created with name as ‘orders’. Now we would create assets under ‘items’ project to setup rule.
![](https://www.hitechpoints.com/wp-content/uploads/2023/06/image-19-1024x328.png)
3) Create Assets
a) Go to ‘orders’ project and click on ‘Add Asset’.
![](https://www.hitechpoints.com/wp-content/uploads/2023/06/image-20-1024x409.png)
b) We need two assets to setup/create rule: 1) Data Object/model and 2) DRL File. We would create ‘Data Object’ first.
![](https://www.hitechpoints.com/wp-content/uploads/2023/06/image-21-1024x415.png)
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.
![](https://www.hitechpoints.com/wp-content/uploads/2023/06/image-22-1024x358.png)
![](https://www.hitechpoints.com/wp-content/uploads/2023/06/image-23-1024x392.png)
d) Now add the required fields by clicking on ‘+ add field’ button in ‘Order.java’ data object.
Field Name | Type |
productName | String |
season | String |
discount | Double |
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.
![](https://www.hitechpoints.com/wp-content/uploads/2023/06/image-24-1024x307.png)
f) Once you added all fields, click on ‘Save’ and then click on ‘Validate’ button to check for any errors.
![](https://www.hitechpoints.com/wp-content/uploads/2023/06/image-25-1024x400.png)
g) Finally click X (close icon) and you will be redirected to Assets page which list your data object that you just created.
![](https://www.hitechpoints.com/wp-content/uploads/2023/06/image-26-1024x299.png)
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.
![](https://www.hitechpoints.com/wp-content/uploads/2023/06/image-28-1024x396.png)
It would create ‘OrderRule.drl’.
![](https://www.hitechpoints.com/wp-content/uploads/2023/06/image-29-1024x455.png)
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.
![](https://www.hitechpoints.com/wp-content/uploads/2023/06/image-30-1024x268.png)
k) Close (X) ‘OrderRule.drl’ guided rule file & you will be redirected to assets screen showing your 2 assets:
![](https://www.hitechpoints.com/wp-content/uploads/2023/06/image-31-1024x361.png)