Chapter 3. Decision Model and Notation (DMN)
Decision Model and Notation (DMN) is a standard established by the Object Management Group (OMG) for describing and modeling operational decisions. DMN defines an XML schema that enables DMN models to be shared between DMN-compliant platforms and across organizations so that business analysts and business rules developers can collaborate in designing and implementing DMN decision services. The DMN standard is similar to and can be used together with the Business Process Model and Notation (BPMN) standard for designing and modeling business processes.
For more information about the background and applications of DMN, see the OMG Decision Model and Notation specification.
3.1. Creating the traffic violations DMN decision requirements diagram (DRD)
A decision requirements diagram (DRD) is a visual representation of your DMN model. Use the DMN designer in Business Central to design the DRD for the traffic violations project and to define the decision logic of the DRD components.
Figure 3.1. DRD for the Traffic Violations example
Prerequisites
- You have created the traffic violations project in Business Central.
Procedure
- On the traffic-violation project’s home page, click Add Asset.
On the Add Asset page, click DMN. The Create new DMN window is opened.
-
In the Create new DMN window, enter
Traffic Violation
in the DMN name field. -
From the Package list, select
com.myspace.traffic_violation
. - Click Ok. The DMN asset in the DMN designer is opened.
-
In the Create new DMN window, enter
- In the DMN designer canvas, drag two DMN Input Data input nodes on to the canvas.
-
Double-click each input node and rename one to
Driver
and the other toViolation
. - Drag a DMN Decision decision node on to the canvas.
-
Double-click the decision node and rename it to
Fine
. -
Click the Violation input node, select the Create DMN Information Requirement icon and click the
Fine
decision node to link the two nodes. - Drag a DMN Decision decision node on to the canvas.
-
Double-click the decision node and rename it to
Should the driver be suspended?
. - Click the Driver input node, select the Create DMN Information Requirement icon and click the Should the driver be suspended? decision node to link the two nodes.
- Click the Fine decision node, select the Create DMN Information Requirement icon, and select the Should the driver be suspended? decision node.
- Click Save and click Save again to confirm.
3.2. Creating the traffic violations DMN custom data types
DMN data types determine the structure of the data that you use within a table, column, or field in a DMN boxed expression for defining decision logic. You can use default DMN data types (such as string, number, or boolean) or you can create custom data types to specify additional fields and constraints that you want to implement for the boxed expression values. Use the DMN designer’s Data Types tab in Business Central to define the custom data types for the traffic violations project.
Figure 3.2. The custom data types tab
Alternately, you can also access the Data Types tab from the Diagram properties tab on the right. From the Diagram properties tab, click Manage from Data type under Information item.
Figure 3.3. Diagram properties tab
The following tables list the Violation
, Driver
, and Fine
custom data types that you will create for this project.
Table 3.1. Driver custom data types
Name | Type |
---|---|
tDriver | Structure |
Name | string |
Age | number |
State | string |
City | string |
Points | number |
Table 3.2. Violation custom data types
Name | Type |
---|---|
tViolation | Structure |
Code | string |
Date | date |
Type | string |
Speed Limit | number |
Actual Speed | number |
Table 3.3. Fine custom data types
Name | Type |
---|---|
tFine | Structure |
Amount | number |
Points | number |
Prerequisites
- You created the traffic violations DMN decision requirements diagram (DRDs) in Business Central.
Procedure
To create the tDriver custom data type, click Add on the Data Types tab, enter
tDriver
in the Name field, selectStructure
from the Type list, and click Save.Figure 3.4. The tDriver custom data type
-
To create the first nested data type, enter
Name
in the Name field of the nested data type, select String from the Type list and click Save. For each of the remaining nested data types, click the three vertical dots next to the tDriver data type, select Insert nested field, and add the following nested data types. Click Save for each nested data type you add.
- Name (string)
- Age (number)
- State (string)
- City (string)
- Points (number)
To create the tViolation custom data type, click Add on the Data Types tab, enter
tViolation
in the Name field, selectStructure
from the Type list, and click Save.Figure 3.5. The tViolation custom data type
-
To create the first nested data type, enter
Code
in the Name field of the nested data type, select String from the Type list and click Save. For each of the remaining nested data types, click the three vertical dots next to the tViolation data type, select Insert nested field, and add the following nested data types. Click Save for each nested data type that you add.
- Code (string)
- Date (date)
- Type (string)
- Speed Limit (number)
- Actual Speed (number)
To add the following constraints to the
Type
nested data type, click Edit → Constraints → Enumeration and add the following constraints. Click the check icon to save each enumeration constraint that you add.-
"speed"
-
"parking"
-
"driving under the influence"
-
To create the tFine custom data type, click Add on the Data Types tab, enter
tFine
in the Name field, selectStructure
from the Type list, and click Save.Figure 3.6. The tFine custom data type
-
To create the first nested data type, enter
Amount
in the Name field of the nested data type, select Number from the Type list and click Save. For each of the remaining nested data types, click the three vertical dots next to the tFine data type, select Insert nested field, and add the following nested data types. Click Save for each nested data type that you add.
- Amount (number)
- Points (number)
- Once all the three custom data types are created, click Save to open the Confirm Save dialog box and click Save again.
3.3. Assigning custom data types to the DRD input and decision nodes
After you create the DMN custom data types, assign them to the appropriate DMN Input Data and DMN Decision nodes in the traffic violations DRD.
Prerequisites
- You have created the traffic violations DMN custom data types in Business Central.
Procedure
- Click the Model tab on the DMN designer and click Diagram properties in the top-right corner of the DMN designer to expose the DRD properties.
-
In the DRD, select the Driver input data node and in the Diagram properties panel, set Data type to
tDriver
. -
Select the Violation input data node and set the Data type to
tViolation
. -
Select the Fine input data node and set the Data type to
tFine
. Select the Should the driver be suspended? decision node and set the following properties:
-
Data type:
string
-
Question:
Should the driver be suspended due to points on his driver license?
-
Allowed Answers:
"Yes","No"
-
Data type:
- Click Save to open the Confirm Save dialog box and click Save again.
You have assigned the custom data types to your DRD’s input and decision nodes.
3.4. Defining the traffic violations DMN decision logic
To calculate the fine and to decide whether the driver is to be suspended or not, you can define the traffic violations DMN decision logic using a DMN decision table and context boxed expression.
Figure 3.7. Fine decision table
Figure 3.8. Should the driver be suspended?
Prerequisites
- You have assigned the DMN custom data types to the appropriate decision and input nodes in the traffic violations DRD in Business Central.
Procedure
- To calculate fine, in the DMN designer canvas, select the Fine decision node and click the Edit icon to open the DMN boxed expression designer.
- Click Select expression → Decision Table.
- For the Violation.Date, Violation.Code, and Violation.Speed Limit parameter fields, right-click and select Delete for each field.
-
Click the Violation.Actual Speed column header and enter the expression
Violation.Actual Speed - Violation.Speed Limit
in the Name field. -
Right-click the Fine parameter field and select either
Insert left
orInsert right
. -
Click the output-2 column sub-header, enter
Amount
in the Name field, and selectnumber
from the Data Type field. -
Similarly, click the output-1 column sub-header, enter
Points
in the Name field, and selectnumber
from the Data Type field. Next, enter the following values in the first row of the decision table:
-
Violation.Type:
"speed"
-
Violation.Actual Speed - Violation.Speed Limit:
[10..30)
-
Amount:
500
Points:
3
Right-click the first row and select
Insert below
to add another row.
-
Violation.Type:
Enter the following values in the second row of the decision table:
-
Violation.Type:
"speed"
-
Violation.Actual Speed - Violation.Speed Limit:
>= 30
-
Amount:
1000
Points:
7
Right-click the second row and select
Insert below
to add another row.
-
Violation.Type:
Enter the following values in the third row of the decision table:
-
Violation.Type:
"parking"
-
Violation.Actual Speed - Violation.Speed Limit:
-
-
Amount:
100
Points:
1
Right-click the third row and select
Insert below
to add another row.
-
Violation.Type:
Enter the following values in the fourth row of the decision table:
-
Violation.Type:
"driving under the influence"
-
Violation.Actual Speed - Violation.Speed Limit:
-
-
Amount:
1000
-
Points:
5
-
Violation.Type:
- Click Save to open the Confirm Save dialog box and click Save again.
- To define the driver suspension rule, return to the DMN designer canvas, select the Should the driver be suspended? decision node, and click the Edit icon to open the DMN boxed expression designer.
- Click Select expression → Context.
-
Click ContextEntry-1, enter
Total Points
as the Name, and selectnumber
as the Data Type. -
Click the cell next to Total Points, select
Literal Expression
from the context menu, and enterDriver.Points + Fine.Points
as the expression. -
In the cell below Driver.Points + Fine.Points, select
Literal Expression
from the context menu, and enterif Total Points >= 20 then "Yes" else "No"
. Click Save to open the Confirm Save dialog box and click Save again.
You have defined how to calculate the fine and the context for deciding when to suspend the driver. You can navigate to the traffic-violation project page and click Build to build the example project and address any errors noted in the Alerts panel.