Create Contexts

A context is a collection of one or more key-value pairs with an optional result field. Each pair is called a context entry. The key attribute within a context entry acts as an identifier to its corresponding value attribute.

You can use a context to collectively document all decision logic related to a particular scenario or entity. Say you need to determine the loan eligibility of an applicant, based on the applicant’s net monthly income and expense. For this purpose, you can create a decision named Loan Eligibility using the Context notation and add expressions or logic for gross monthly income, monthly expense, and net monthly income. Then, you can either add a result field (within the context) that evaluates the net income and expense for loan eligibility, or you can choose to evaluate these within another decision.

Without a result field, a context decision returns multiple key-value pairs as output. In this case, you can invoke any context entry from another decision.

If you add a result field, the output of this field is displayed as the context’s output. Here, you can only invoke the context’s result from another decision.

To create a decision with the Context notation:
  1. Add a new decision element to the model.
    1. In graph view, click Expand Expand/Collapse icon next to Decision on the diagram palette. Select Context and drag it onto the canvas. Double-click the element to edit its logic. You can also edit the context's logic from the properties pane; select the element, then select Open Properties Open Properties icon, and in the properties pane click Edit Edit icon next to the Name field.
      Click Close Close icon to return to the canvas.
    2. In list view, click Add new decision Add New Decision icon in the Decisions bar and select Context from the Create Decision window.
    An empty Context is created.
  2. Click Add entry to create a new context entry. A key-value pair is created with the expression notation selected by default in the Value field.
  3. To change the logical notation for an entry, click the decision logic icon in the Key field to open the Change Value menu. Select a different notation from the available options.
  4. In the Key field of a context entry, enter a unique name.
  5. In the corresponding Value field, configure the logic for the selected notation. You can use input variables or built-in functions to define the logic.
  6. Repeat steps 2 to 5 to add another entry into the context.
  7. Drag and drop context entries to reorder them within the context.
  8. Optionally, click Add result to include a result field for the context. A key-value pair appears with the expression notation in the Value field and the context name in the Key field.
  9. Similar to other entries, you can change the notation for the result field and define a logic using other context entries, input variables, or built-in functions.
  10. Click Save to save and validate changes manually. Changes you make within the decision model are also automatically saved and validated from time to time. Errors, if any, are displayed within the decision.

    To delete a context entry, click the decision logic icon in the Key field and select Delete.

The following image shows a context with a result field that determines the loan eligibility of applicants::

Description of dmn-context.png follows
Description of the illustration dmn-context.png

The output of the result field is the context’s output. In this case, the context returns a true or false regarding an applicant’s loan eligibility. You can reference the context’s result in other decisions within the model using the context name (for example, Loan Eligibility).

The following image shows a context without a result field and an expression decision referencing multiple context entries to determine the loan eligibility of applicants:

Description of dmn-context-no-result.png follows
Description of the illustration dmn-context-no-result.png

The output of this context is a list containing results of all three context entries. To reference a particular context entry from another decision, use the format ContextName.EntryKey (for example, Income.Expenses). Within a context, an entry can only reference entries that are above it.

Note:

If you add a function as one of the context entries, the context as a whole doesn’t return a result. However, you will still be able to invoke results of individual context entries throughout the decision model.