Questo contenuto non è disponibile nella lingua selezionata.
Chapter 16. Advanced process concepts and tasks
16.1. Invoking a Decision Model and Notation (DMN) service in a business process Copia collegamentoCollegamento copiato negli appunti!
You can use Decision Model and Notation (DMN) to model a decision service graphically in a decision requirements diagram (DRD) in Business Central and then invoke that DMN service as part of a business process in Business Central. Business processes interact with DMN services by identifying the DMN service and mapping business data between DMN inputs and the business process properties.
As an illustration, this procedure uses an example TrainStation project that defines train routing logic. This example project contains the following data object and DMN components designed in Business Central for the routing decision logic:
Example Train object
Figure 16.1. Example Compute Rail DMN model
Figure 16.2. Example Rail DMN decision table
Figure 16.3. Example tTrain DMN data type
For more information about creating DMN models in Business Central, see Designing a decision service using DMN models.
Prerequisites
- All required data objects and DMN model components are defined in the project.
Procedure
-
In Business Central, go to Menu
Design Projects and click the project name. - Select or create the business process asset in which you want to invoke the DMN service.
- In the process designer, use the left toolbar to drag and drop BPMN components as usual to define your overall business process logic, connections, events, tasks, or other elements.
To incorporate a DMN service in the business process, add a Business Rule task from the left toolbar or from the start-node options and insert the task in the relevant location in the process flow.
For this example, the following
Accept Trainbusiness process incorporates the DMN service in theRoute To Railnode:Figure 16.4. Example
Accept Trainbusiness process with a DMN serviceSelect the business rule task node that you want to use for the DMN service, click Properties in the upper-right corner of the process designer, and under Implementation/Execution, define the following fields:
-
Rule Language: Select
DMN. -
Namespace: Enter the unique namespace from the DMN model file. Example:
https://www.drools.org/kie-dmn -
Decision Name: Enter the name of the DMN decision node that you want to invoke in the selected process node. Example:
Rail DMN Model Name: Enter the DMN model name. Example:
Compute RailImportantWhen you explore the root node, ensure that the Namespace and DMN Model Name fields consist of the same value in BPMN as DMN diagram.
-
Rule Language: Select
Under Data Assignments
Assignments, click the Edit icon and add the DMN input and output data to define the mapping between the DMN service and the process data. For the
Route To RailDMN service node in this example, you add an input assignment forTrainthat corresponds to the input node in the DMN model, and add an output assignment forRailthat corresponds to the decision node in the DMN model. The Data Type must match the type that you set for that node in the DMN model, and the Source and Target definition is the relevant variable or field for the specified object.Figure 16.5. Example input and output mapping for the
Route To RailDMN service node- Click Save to save the data input and output data.
Define the remainder of your business process according to how you want the completed DMN service to be handled.
For this example, the Properties
Implementation/Execution On Exit Action value is set to the following code to store the rail number after the Route To RailDMN service is complete:Example code for
On Exit Actiontrain.setRailNumber(rail);
train.setRailNumber(rail);Copy to Clipboard Copied! Toggle word wrap Toggle overflow If the rail number is not computed, the process reaches a
No Appropriate Railend error node that is defined with the following condition expression:Figure 16.6. Example condition for
No Appropriate Railend error nodeIf the rail number is computed, the process reaches an
Accept Trainscript task that is defined with the following condition expression:Figure 16.7. Example condition for
Accept Trainscript task nodeThe
Accept Trainscript task also uses the following script in PropertiesImplementation/Execution Script to print a message about the train route and current rail: com.myspace.trainstation.Train t = (com.myspace.trainstation.Train) kcontext.getVariable("train"); System.out.println("Train from: " + t.getDepartureStation() + ", to: " + t.getDestinationStation() + ", is on rail: " + t.getRailNumber());com.myspace.trainstation.Train t = (com.myspace.trainstation.Train) kcontext.getVariable("train"); System.out.println("Train from: " + t.getDepartureStation() + ", to: " + t.getDestinationStation() + ", is on rail: " + t.getRailNumber());Copy to Clipboard Copied! Toggle word wrap Toggle overflow After you define your business process with the incorporated DMN service, save your process in the process designer, deploy the project, and run the corresponding process definition to invoke the DMN service.
For this example, when you deploy the TrainStation project and run the corresponding process definition, you open the process instance form for the
Accept Trainprocess definition and set thedeparture stationanddestination stationfields to test the execution:Figure 16.8. Example process instance form for the
Accept Trainprocess definitionAfter the process is executed, a message appears in the server log with the train route that you specified:
Example server log output for the
Accept TrainprocessTrain from: Zagreb, to: Belgrade, is on rail: 1
Train from: Zagreb, to: Belgrade, is on rail: 1Copy to Clipboard Copied! Toggle word wrap Toggle overflow