Task 3: Adding nodes

You add two nodes for the weather to the decision model. When you run the model, it produces a greeting and weather advice.

About this task

In this task, you...

  • Add an input node for the rain forecast, and a decision node for weather advice to the model.
  • Add a decision table, and define the logic for the weather advice.
  • Run the model to check your changes.

Step 1: Adding nodes to the model

About this task

In this step, you add a decision node and an input node for weather advice to the model.

Procedure

  1. Click My Service to open your decision service. Then, click My Model to open your decision model.
  2. Click Add decision to create a decision node:
    ""
  3. In the right panel, change the Node name field of the new node to Weather advice. Leave string as the output type.
  4. Hover over the error icon Error icon to see its message:
    The node 'Weather advice' must have one or more links to or from other nodes.

    The message is also shown in the Error report tab. Each node must be connected to at least one other node.

  5. Hover over the Weather advice node, and click the Add input icon:
    ""
    Tip: Depending on your system, you might have to select the node before you can hover over it to see the toolbar.
  6. In the right panel, change the Node name field to Rain forecast.
  7. Expand the Output type field, and select integer from the menu.
  8. Hover over the Weather advice node, and click the Connect to another node icon:
    ""
  9. Drag the line to the Daily advice node, and click the node to complete the connection.
    Now, data flows from the Rain forecast node to the Weather advice node, and decisions flow from the Weather advice node to the Daily advice node:
    Image shows the decision model.

Step 2: Adding a decision table

About this task

A decision table groups business rules that share the same logic but have different values. Each row in a decision table represents a complete business rule. The decision table has separate columns for condition values and action values. When data enters a decision table, it is matched to values in condition columns and the associated action value is used in the output of the decision table (see Working with decision tables).

In this step, you add a decision table to the Weather advice node.

Procedure

  1. Select the Weather advice node.
  2. Click the Logic tab, click the Add button Add, and select Decision table.
  3. Enter weather table in the Name field of the new table, select Rain forecast for the condition columns, and then click Create.
  4. Enter the following values in the decision table. To add a value to a cell, double-click the cell. Alternatively, you can copy the content of the table below and paste it directly into the decision table.
    Tip: You can resize the decision table by dragging its borders.
    Rain forecast Weather advice
    min max  
    0 20 Nice day. Enjoy the weather!
    20 80 Risk of rain. Might need an umbrella.
    80 100 Rainy day. Take an umbrella.
  5. Right-click 100 in the decision table, and select Change operator. By default, the operator is set to [..[. Select [..] to change the operator. Now, the value is included in the conditions.
  6. Click Back to the diagram to close the editor. Now, the model outputs a greeting, and advice from the weather decision table.
  7. Select the Daily advice node.
  8. In the Logic tab, open the Advice rule and make the following changes.
    Tip: As with Hello, add a space after ! to leave a gap before the weather advice in the output.
    if
        Name is defined
    then
        set decision to `Hello { 'Name' }! { 'Weather advice' }` ;

    Now, you run the model to see the results.

Step 3: Running the model

About this task

In this step, you run your changes as explained in Task 1: Making a decision service.

Procedure

  1. Click the Run tab.
  2. Add the following test data:
    Again, the form uses the JSON representation of the name of an input node. Here, Name and Rain forecast become name and rainForecast. For more information, see Modeling data.
    • name: Robin
    • rainForecast: 87
      Tip: For rainForecast, you can type the number or select it with the arrow buttons.
  3. Click Run. You get the following message:
    Hello Robin! Rainy day. Take an umbrella.
  4. Delete the test data for the next task.

What to do next

In the next task, you add a data model to your decision service to enumerate temperatures.