Book a Demo
Prev Next

Example - Loan Installment Calculation

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; the 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 and separated by a colon, as shown here.

Then click on the Save button on the toolbar to save the expression, and click on the button 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:

To edit an expression, right-click on the expression (in the right-hand field) and select the 'Edit Expressions' menu option. The 'Expression' dialog displays. Click on the required line and press Ctrl+Space to show the Intelli-sense menu:

  • All the Context Entry Variables earlier than the current one will be included (the Context Entry Variables later than the current one are excluded)
  • For a Business Knowledge Model (BKM), all the parameters will be included
  • For a 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.

Simulation of Business Knowledge Model

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

Click on the Save button and then on the Simulation button on the toolbar; the test result will be presented in the Boxed Context expression.

  • 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.06'
  • The Business Knowledge Model (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 BKM without knowing the context so that later on it can be invoked by a Decision or another BKM.