Book a Demo

Please note : This help page is not for the latest version of Enterprise Architect. The latest help can be found here.

Prev Next

Example - Loan Installment Calculation

An example of a DMN Expression for am BKM using Boxed Content as modeled in Sparx Systems Enterprise Architect.

The Business Knowledge Model (BKM) Installment calculation is implemented as Boxed Context.

  • The BKM defines four parameters: Product Type, Rate, Term and Amount
  • The Boxed Context defines two variable-expression pair entries, these variables serve as 'local variables' that can be used in later expressions
  • Return value: The expression can use the value of 'local variables'
  • Any expressions in a Boxed Context can use built-in functions, which are defined in the customizable Template — DMN Library; for example, functions PMT(...) and decimal(...) are used in this example

Specify Type to Context Entry Variable

In general, the expression and variables do not have to specify a type, which is inferred from the value provided. This feature is supported generically by JavaScript, which is used for Enterprise Architect's DMN Simulation.

However, if you want to generate code from a DMN model to compiled languages such as Java, C++ or C#, you will have to specify the type for each Context Entry Variable. Otherwise, if you validate the model, you will see warnings such as:

Right-click on the Context Entry Variable (Monthly Fee, Monthly Repayment) in this model.

Select the 'Show Variable Type' option.

Now type in the variable type, appending it to the variable name, separated by a colon (see the field above Monthly Fee).

Then click on the Save button on the toolbar to save the expression, and click on the Validation button (seventh from the left in the toolbar) to validate the model again.

Expression Editor and Intelli-sense Support

The parameter and Context Entry's variable name can contain spaces, according to the FEEL language specification. This feature makes the expression easy to read. In order to help you edit the expressions with less typing and making fewer mistakes, Enterprise Architect provides Intelli-sense support for editing expressions:

     Right-click on the Expression | Edit Expressions...   the 'Expression' dialog displays

     Press Ctrl+Space to show the Intelli-sense menu:

  • All the Context Entry Variables earlier than the current one will be included (the context entries later than the current one are excluded)
  • For BKM, all the parameters will be included
  • For Decision, all the required Decisions will be included

The DMN model can be generated as source code for JavaScript, Java, C# and C++. Since some languages might have different syntax for some expressions, Enterprise Architect provides language override pages for each language. If no override code is specified for a language, the expression defined for the FEEL language will be used.

In the generated code, the space inside a variable name will be replaced by an underscore.

Test Harness for Business Knowledge Model

Select the 'Input Parameter Values for Simulation' tab and complete the fields.

Using the DMN Input Parameter Values for Simulation using Sparx Systems Enterprise Architect.

Click on the Test Harness button on the toolbar; the test result will be presented in the Boxed Context.

Using the FEEL expression editor for a DMN model using Sparx Systems Enterprise Architect.

  • The runtime parameter value will be displayed; for example, 'Rate = 0.00375'
  • The 'Context Entry' variable's runtime value will be displayed; for example, 'Monthly Repayment = 1520.05'
  • The BKM's result will be evaluated by the last entry and the values displayed on the declaration line; for example, 'return = 1540.06'

You can use this functionality to unit test a BusinessKnowledgeModel without knowing the context and later on invoked by a Decision or other BusinessKnowledgeModel.

Menu options are available for this tool bar button. For more information, see the Business Knowledge Model and Test Harness Help topic.