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.
図3.8 Fine decision table
図3.9 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 the fine, in the DMN designer canvas, select the Fine decision node and click the Edit icon to open the DMN boxed expression designer.
図3.10 Decision node edit icon
Click Select expression
Decision Table. 図3.11 Select Decisiong Table logic type
- 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 Expression 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 pull-down menu. -
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 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
from the Data Type pull-down menu. -
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.
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.