Search

Chapter 5. Decision Model and Notation (DMN)

download PDF

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.

5.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 5.1. DRD for the Traffic Violations example

dmn traffic violations drd

Prerequisites

  • You have created the traffic violations project in Business Central.

Procedure

  1. On the traffic-violation project’s home page, click Add Asset.
  2. On the Add Asset page, click DMN. The Create new DMN window is opened.

    1. In the Create new DMN window, enter Traffic Violation in the DMN name field.
    2. From the Package list, select com.myspace.traffic_violation.
    3. Click Ok. The DMN asset in the DMN designer is opened.
  3. In the DMN designer canvas, drag two DMN Input Data input nodes onto the canvas.

    Figure 5.2. DMN Input Data nodes

    library objects
  4. In the upper-right corner, click the diagram properties icon.
  5. Double-click the input nodes and rename one to Driver and the other to Violation.
  6. Drag a DMN Decision decision node onto the canvas.
  7. Double-click the decision node and rename it to Fine.
  8. Click the Violation input node, select the Create DMN Information Requirement icon and click the Fine decision node to link the two nodes.

    Figure 5.3. Create DMN Information Requirement icon

    info requirement
  9. Drag a DMN Decision decision node onto the canvas.
  10. Double-click the decision node and rename it to Should the driver be suspended?.
  11. 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.
  12. Click the Fine decision node, select the Create DMN Information Requirement icon, and select the Should the driver be suspended? decision node.
  13. Click Save.

    Note

    As you periodically save a DRD, the DMN designer performs a static validation of the DMN model and might produce error messages until the model is defined completely. After you finish defining the DMN model completely, if any errors remain, troubleshoot the specified problems accordingly.

5.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 5.4. The custom data types tab

dmn custom datatypes tab

The following tables list the tDriver, tViolation, and tFine custom data types that you will create for this project.

Table 5.1. tDriver custom data type
NameType

tDriver

Structure

Name

string

Age

number

State

string

City

string

Points

number

Table 5.2. tViolation custom data type
NameType

tViolation

Structure

Code

string

Date

date

Type

string

Speed Limit

number

Actual Speed

number

Table 5.3. tFine custom data type
NameType

tFine

Structure

Amount

number

Points

number

Prerequisites

  • You created the traffic violations DMN decision requirements diagram (DRDs) in Business Central.

Procedure

  1. To create the tDriver custom data type, click Add a custom Data Type on the Data Types tab, enter tDriver in the Name field, and select Structure from the Type list.
  2. Click the check mark to the right of the new data type to save your changes.

    Figure 5.5. The tDriver custom data type

    dmn tDriver custom datatype
  3. Add each of the following nested data types to the tDriver structured data type by clicking the plus sign next to tDriver for each new nested data type. Click the check mark to the right of each new data type to save your changes.

    • Name (string)
    • Age (number)
    • State (string)
    • City (string)
    • Points (number)
  4. To create the tViolation custom data type, click New Data Type, enter tViolation in the Name field, and select Structure from the Type list.
  5. Click the check mark to the right of the new data type to save your changes.

    Figure 5.6. The tViolation custom data type

    dmn tViolation custom datatype
  6. Add each of the following nested data types to the tViolation structured data type by clicking the plus sign next to tViolation for each new nested data type. Click the check mark to the right of each new data type to save your changes.

    • Code (string)
    • Date (date)
    • Type (string)
    • Speed Limit (number)
    • Actual Speed (number)
  7. To add the following constraints to the Type nested data type, click the edit icon, click Add Constraints, and select Enumeration from the Select constraint type drop-down menu.

    • speed
    • parking
    • driving under the influence
  8. Click OK, then click the check mark to the right of the Type data type to save your changes.
  9. To create the tFine custom data type, click New Data Type, enter tFine in the Name field, select Structure from the Type list, and click Save.

    Figure 5.7. The tFine custom data type

    dmn tFine custom datatype
  10. Add each of the following nested data types to the tFine structured data type by clicking the plus sign next to tFine for each new nested data type. Click the check mark to the right of each new data type to save your changes.

    • Amount (number)
    • Points (number)
  11. Click Save.

5.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

  1. Click the Model tab on the DMN designer and click the Properties diagram properties icon in the upper-right corner of the DMN designer to expose the DRD properties.
  2. In the DRD, select the Driver input data node and in the Properties panel, select tDriver from the Data type drop-down menu.
  3. Select the Violation input data node and select tViolation from the Data type drop-down menu.
  4. Select the Fine decision node and select tFine from the Data type drop-down menu.
  5. 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
  6. Click Save.

You have assigned the custom data types to your DRD’s input and decision nodes.

5.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 5.8. Fine expression

dmn gs fine decision table

Figure 5.9. Should the driver be suspended expression

dmn gs context table

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

  1. 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.

    Figure 5.10. Decision node edit icon

    decision node edit
  2. Click Select expression Decision Table.

    Figure 5.11. Select Decisiong Table logic type

    select logic type
  3. For the Violation.Date, Violation.Code, and Violation.Speed Limit columns, right-click and select Delete for each field.
  4. Click the Violation.Actual Speed column header and enter the expression Violation.Actual Speed - Violation.Speed Limit in the Expression field."
  5. 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.

  6. 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.

  7. 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.

  8. 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
  9. Click Save.
  10. 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.
  11. Click Select expression Context.
  12. Click ContextEntry-1, enter Total Points as the Name, and select number from the Data Type drop-down menu.
  13. Click the cell next to Total Points, select Literal expression from the context menu, and enter Driver.Points + Fine.Points as the expression.
  14. In the cell below Driver.Points + Fine.Points, select Literal Expression from the context menu, and enter if Total Points >= 20 then "Yes" else "No".
  15. 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.

Red Hat logoGithubRedditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

© 2024 Red Hat, Inc.