Ready to create a decision model?

Ever leave the house and wish you’d better prepared for the weather?

Let’s create a process application to fix that. When prompted, you input the temperature and rain forecast, and the application decides whether you should bring:

  • An umbrella, for warm and rainy weather

  • A raincoat, for cold and rainy weather

  • An overcoat, for cold and dry weather

  • Nothing, for warm and dry weather

Using this example, let’s explore the entire decision model development life cycle—from creating a decision model, defining its decision logic, activating it on the DMN server, and using a decision service in a process.

Create a Simple Application

First, let’s create an application for the decision. Its process starts with a web form, which has two input fields where you enter temperature and rain forecast numbers. It then uses a decision element to call the decision service. Lastly, a human task element displays the decision result, which tells you what to bring for the day based on the weather.

  1. Create an application.

    Click Processes and then click Process Applications to go to the Process Applications page, and then click Create.

    Click Create an Application. Enter a name (What To Bring) and click Create.

  2. Create a process.

    In the Create a Process pane, click Start with a form, enter a process name (Decision Process), and click Create.

  3. Add a decision and human task.

    On the Decision Process tab, expand System on the Elements palette, drag a Decision element to the process, and drop it after the start event.

    Expand Human on the palette, drag a Submit element to the process, and drop it after the decision element.

  4. Rename the flow elements.

    Double-click the flow elements and rename the start event to Input Forecast, the decision to Decide What to Bring, and the human task to Display Result.

    Description of decision-process.png follows
    Description of the illustration decision-process.png

  5. Add a web form.

    Select the Input Forecast element, click Menu Menu icon, and select Open Properties. In the Title field, enter a name (Forecast) to display for the application.

    Click Create New Form Add icon next to the Form field. Enter InputForecastWebForm in the Name field, select the Open Immediately check box, and click Create.

  6. Add the forecast input fields to the web form.

    From the Basic palette, drag and drop two Number controls and one Input Text control onto the canvas. Select each control and edit its Label field in the Properties pane, changing the number controls to Temperature and Rain, and the text control to What To Bring.

    Select the What To Bring control, scroll down the General tab, and select the Hide check box. Notice that the control becomes dimmed to indicate it’s hidden.

  7. Add a presentation to display results.

    Click the form outside a control. On the Form tab, click Add Presentation Add Presentation icon next to Presentations. In the Select Presentation Type dialog box, select Clone. In the Create Presentation dialog box, select Main in the Select from Previous Presentation field, enter a name for the new presentation (Result), and click Create. On the new Result presentation, select the What To Bring control and deselect the Hide check box.

    Want to learn more about web forms? See Create Web Forms.

    Description of webform-presentation.png follows
    Description of the illustration webform-presentation.png

  8. Save the application.

    Want to learn more about working with applications? See Create and Manage Applications.

  9. Return to the process by clicking the Decision Process tab. Open the properties for the Display Result human task. Click Browse Browse icon next to the Form field and select InputForecastWebForm. In the Presentation field, select Result.

Create a Decision Model

A decision model does what its name implies: it lets you define how decisions will work. It contains a list of decisions, input data, and other definitions.

To create a decision model:
  1. Return to the Process Applications page by clicking Back Back icon on the navigation pane.
  2. On the navigation pane, click Decision Models.

    You can use a decision model in multiple applications.

  3. Click Create.
  4. Click Create a Decision Model.
  5. In the Create Decision Model dialog box, enter a name for the model (What To Bring Decision Model) and click Create.

    The decision model editor opens in a new page named with the title you entered. Notice that the editor contains a central pane labeled Decisions on which you construct decisions, with expandable Services and Input Data side panes.

    See Work with Decision Models.

    Description of create-decision-model.png follows
    Description of the illustration create-decision-model.png

Add Decisions

Let’s set up our decision model framework. In Decision Model and Notation (DMN), a decision model answers a central question. This model answers the question: what to bring to be prepared for the weather?

  1. Add a result decision.
    1. Click Add new decision Add New Decision icon in the Decisions bar.
    2. In the Create Decision dialog box, enter a decision name (What To Bring), select Empty Logic, and click Create. The new decision displays in the Decisions pane. You can change its logic type later.
  2. Create two more decisions to act as supporting decisions.

    Most decisions models include supporting decisions that feed into the result decision. Deciding what to bring requires supporting decisions to answer these questions: 1) Will it be warm or cold? 2) Will it rain?

    1. Click Add new decision Add New Decision icon to create another decision. Enter a decision name (Temperature), select Empty Logic, and click Create.
    2. Repeat to create another empty logic decision called Rain.

    Description of decisions.png follows
    Description of the illustration decisions.png

    Notice that the topmost decision is the main result decision. Supporting decisions are listed below the main result decision. Decision order is important.

    • Decision logic can reference the result of supporting decisions by name. For example, the decision table for What To Bring can reference the result of supporting decisions Rain and Temperature by name.

    • Supporting decisions must always be beneath the decisions that reference them. Decision logic can’t “see” the decisions listed above. To change the order of decisions in the model, drag the decision by its dotted handle and drop it at the desired position so that supporting decisions are always beneath the decisions that they support.

Define Input

It’s hard to make a good decision without input (or data). For our “What to Bring for the Weather” example, the input will be two numbers: temperature and rain percent forecasts. Let’s set up their definitions.

  1. Click Show data panel Show data panel icon to expand the Input Data pane.
  2. Add a complex type definition for the forecasts.
    1. In the Type Definition section, click Add new item definition Add Input Variable icon.
    2. In the Name field, enter ForecastType.
    3. In the Mode field, select Complex.
    4. Click Add Component next to Define Type Attributes to add two attributes.
    5. For the first attribute, enter Temperature for its name and select Number as its mode. Click Close to return to the Add Type Definition panel.
    6. For the second attribute, enter Precipitation for its name and Number as its mode.
    7. Click Close.
  3. Add an input variable that uses the Forecast type definition you just created.
    1. In the Input Data section, click Add new input data Add new input data icon.
    2. In the Name field, enter Forecast.
    3. In the Mode field, select Other Type.
    4. In the Other Types field, select ForecastType and click Close.
  4. Click Hide data panel Hide data panel icon to collapse the Input Data pane.

    Want to learn more about input? See Define Decision Input and Type.

Model Decision Logic

Now let’s change the empty logic of the decisions. You can configure decision logic in a variety of ways, but here you’ll create a Boolean expression, an if-then-else expression, and a decision table.

  1. Configure a Boolean expression for the rain forecast.
    1. Change the Rain decision to an Expression decision. Select the Expression logic from the list that is displayed within the decision.

      Notice that the decision’s icon changed to an expression icon and the decision expanded. Also, a number and a yellow circle with an exclamation point Validation error icon indicate a validation error because you haven’t entered an expression yet.

      See Adding and Ordering Decisions for information on other fields in the Add/Edit Decision window.

    2. Enter the expression using the input data you already defined. Click the Enter expression field and enter this condition:

      Forecast.Precipitation>80

      Description of decision-logic1.png follows
      Description of the illustration decision-logic1.png

      When the precipitation input value is greater than 80 percent, this Boolean expression will be true (rain is likely); otherwise it will be false (rain is unlikely).

      Want to learn more about the expression language? See Define Expressions with the Friendly Enough Expression Language (FEEL).

    3. Click Collapse Collapse icon to collapse the Boolean expression. Notice that the validation error no longer displays because the expression is now valid.
  2. Configure an if-then-else decision for the temperature forecast.
    1. Expand the Temperature decision and change its type to If-Then-Else. The decision expands and shows validation errors for items you need to complete.
    2. Complete the decision’s if, then, and else expression fields as follows:
      • if: Forecast.Temperature>65

      • then: “warm”

      • else: “cold”

      Because “warm” and “cold” values are strings, you must include quotation marks around the values. (Depending on your location, you may want to adjust the temperature condition of >65 from degrees in Fahrenheit to >18 in Celsius.)

      Description of decision-logic2.png follows
      Description of the illustration decision-logic2.png

    3. Collapse the decision and verify that the validation errors no longer display.
  3. Configure a decision table for the What To Bring decision.

    A decision table lets you model input, output, and rules in a compact way. It derives a final output decision using input data and the results of other decisions.

    In the example, the temperature and rain input decisions each have two possibilities, resulting in a total of four output possibilities.

    Temperature (input) Rain (input) What To Bring (output)
    warm true umbrella
    cold true raincoat
    cold false overcoat
    warm false nothing
    1. Expand the What To Bring decision and change its type to Decision Table.
    2. Expand the decision and explore the table started for you.
      • The yellow column is for output, and is always the final column of the table. What To Bring is already designated as your output decision.

      • The adjacent grey column is for input. You’ll add a second input column, using one of the controls located above the output column.

      • Rows are for rules. A row labeled 1 is already listed.

      • Above the 1 in rule 1 is a U, indicating that the table uses a unique hit policy. The hit policy determines the output of a decision table when more than one rule matches the input data.

        See Configure a Hit Policy.

    3. Configure the possible values for the What To Bring output column.
      • In the What To Bring column, click Enter Allowed Values.

      • In the resulting dialog, select Text in the Mode field, select list of values in the Constraints field, and enter the following values: umbrella, raincoat,overcoat,nothing.

      • Click Close.

      Description of decision-input-configuration.png follows
      Description of the illustration decision-input-configuration.png

    4. Configure the Temperature input column.

      In the Enter Expression cell of the gray input column, press Ctrl+Space to open a pop-up menu. Select Temperature from the menu. For an input column, the Allowed Value cell is auto-populated based on the input expression.

      To specify a different set of allowed values, see Defining Decision Table Input.

    5. Add and configure the Rain input column.
      • Click the Temperature input column and select Add column after Add column after icon.

      • In the Enter Expression cell, press Ctrl+Space to open a pop-up menu. Select Rain from the menu. The Allowed Value cell is auto-populated with Boolean values.

    6. Add and configure rules.
      • In row 1, click the cell below Temperature and select warm.

        Notice the String mode icon icon in the cell, which stands for text. Clicking this icon, you can toggle between Text Text mode icon, Any, and Advanced Advanced mode icon modes for all the cells in this column.

        See Configure Rules.

        In the text mode, text strings are automatically italicized and quotation marks aren’t needed.

      • Click the cell below Rain and select true. Notice the Boolean icon icon in the cell, which stands for Boolean. Clicking this icon, you can toggle between Boolean Boolean icon, Any, and Advanced Advanced mode icon modes for all the cells in this column.

      • Click the cell below What To Bring and select umbrella from the auto-suggest menu. If needed, set the cell’s mode to Text. Quotation marks aren’t needed.

    7. Click Add rule after Add rule after icon three times to add three rows to the table.
    8. Complete rules 2 through 4 of the decision table:
      • For rule 2, select cold, true, and raincoat.

      • For rule 3, select cold, false, and overcoat.

      • For rule 4, select warm, false, and nothing.

      Description of decision-table.png follows
      Description of the illustration decision-table.png

    9. Collapse the decision.
Want to learn more about decision model types? See Model Decision Logic.

Test Your Decisions

Verify that the model produces the results you want by testing it with input values.

  1. Click Test Test icon.
  2. In the Test Decision Model pane, enter values in the Temperature and Precipitation fields and click Start Test. For example, enter 85 into both fields.

    The Decision Model Result pane displays decision results. Click each green check mark to see the decision’s result.

    Description of decision-model-result.png follows
    Description of the illustration decision-model-result.png

  3. Click Go Back, and repeat step 1 and 2 to test each decision rule’s outcome.
    Temperature (F) Precipitation % Outcome

    85

    85

    • What to Bring: umbrella

    • Temperature: warm

    • Rain: true

    50

    85

    • What to Bring: raincoat

    • Temperature: cold

    • Rain: true

    50

    50

    • What to Bring: overcoat

    • Temperature: cold

    • Rain: false

    85

    50

    • What to Bring: nothing

    • Temperature: warm

    • Rain: false

  4. Save the decision model.

    Want to learn more? See Test Decisions.

Create a Service

After you complete and test the decision logic, create a RESTful service to communicate with Process. The decision service specifies the decision and input data you want to expose.

  1. Expand the Services pane, and click Add new service Add new service icon.
  2. Enter a name for the decision service (What To Bring Service) and click OK.
  3. From the Decisions pane, drag What To Bring (the title of your result decision) to the Output Decisions field in the Services pane and drop when the field turns blue. The service name displays above the field. Validation errors display because you haven’t specified input data yet.
  4. From the Input Data pane, drag the Forecast input data to the Input Data field in the Services pane and drop when the field turns blue.

    Description of decision-services.png follows
    Description of the illustration decision-services.png

    You can output multiple decisions and input multiple data items in a service. See Expose Decisions as Services.

  5. Click Save.

Activate a Decision Snapshot

To use a decision model, you must create a snapshot of it and activate the snapshot on the DMN server.

  1. In the decision model editor toolbar, click Activate.
  2. In the Create Snapshot and activate it dialog box, enter a name (What to Bring Snapshot) and click Activate.
  3. In the decision model editor toolbar, click Snapshots.

    Notice that the snapshot you just activated is listed, along with any other activated snapshots. Here you can:

    • Activate or deactivate a selected snapshot.

    • Delete a snapshot. You must deactivate a snapshot before you can delete it.

    • View a read-only version of the snapshot.

    • Export a snapshot, which you can later import into a new decision model and edit its contents.

    Description of manage-snapshots-dmn.png follows
    Description of the illustration manage-snapshots-dmn.png

    Want to learn more about managing decision model snapshots and their versions? See Manage Decision Model Snapshots.

  4. Click Close.

Use the Decision in Your Application

Now let’s use your activated decision snapshot in a process within an application.

  1. Return to the Process Applications page by clicking Back Back icon in the navigation pane.

    Notice that the page displays both the application and the decision model you created.

    Description of proc-app-page-dmn.png follows
    Description of the illustration proc-app-page-dmn.png

  2. Open the What To Bring application you created.
  3. Open the decision process. Select the decision element you added (Decide What to Bring), click Menu Menu icon , and select Open Properties.
  4. On the Properties pane, click Use Decision Model Use Decision Model icon next to the Decision Model field.
  5. In the Use an Activated Decision Model dialog box, select the snapshot you created and activated (WhatToBringSnapshot), and click Use.

    Description of activate-decision-model.png follows
    Description of the illustration activate-decision-model.png

    Process brings the activated decision model snapshot into the application and performs behind-the-scenes operations such as importing data types and defining the REST connector to the service. See Add Decisions to Applications and Processes.

    Notice that the Properties pane now lists the decision model and service you selected to use.

    Description of decision-process-properties.png follows
    Description of the illustration decision-process-properties.png

  6. Click Collapse Pane Collapse pane icon to close the properties pane.

Map Data to and from the Decision

Configuring the data mapping is the last key piece in configuring a decision model. The data needs to flow from the web form into the decision and its result must flow out of the decision so the human task can display it.

  1. On the Decision Process tab, let’s view the data association that was automatically configured for the Input Forecast start activity and the Display Result human task.
    1. Select the Input Forecast element and click Data Association in the toolbar. Expand the values in both side panes. Notice that values entered into the web form are written to a data object called inputForecastWebFormDataObject. Click Cancel.
    2. Select the Display Result element and click Data Association in the toolbar. Notice that for input, the same data object—inputForecastWebFormDataObject—is used to write values back to the web form. Click Cancel.
  2. Map input and output data association for the decision element.

    The decision needs to use the input values (rain, temperature) contained in inputForecastWebFormDataObject and output the decision’s result (what to bring) into the data object.

    1. Open data association for the Decide What to Bring element. With the Input tab selected, expand the values in both side panes.
    2. Map the rain and temperature values as follows:

      inputForecastWebFormDataObject.rain to body.forecast.precipitation

      inputForecastWebFormDataObject.temperature to body.forecast.temperature

    3. With the Output tab selected, map the Decide What to Bring value as follows:

      bodyOutput.interpretation to inputForecastWebFormDataObject.whattobring

  3. Click Apply.

Try Your Decision in Runtime

Let’s try running the application in test mode as an end user.

  1. From the toolbar, click Test.
  2. On the Test Application tab, click Activate. In the Activate to Test dialog box, leave the Add Me to All Roles check box selected and click Activate.
  3. After the application activates successfully, click Try in Test Mode. When the new browser tab opens displaying runtime options, click Forecast from the My Apps pane.
  4. In the form, enter temperature and rain values, and click Submit.
  5. Click My Tasks and open your new task. The What To bring field displays the decision’s result based on the values you entered.