<commit_before>[id='dmn-execution-business-process']
= Invoking a Decision Model and Notation (DMN) service in a business process

You can use Decision Model and Notation (DMN) to model a decision service graphically in a decision requirements diagram (DRD) in {CENTRAL} and then invoke that DMN service as part of a business process in {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 {CENTRAL} for the routing decision logic:

.Example `Train` object
[source,java,align="center"]
----
public class Train {

     private String departureStation;

     private String destinationStation;

     private BigDecimal railNumber;

     // Getters and setters
}
----

.Example `Compute Rail` DMN model
image::dmn/dmn-execution-graph.png[]

.Example `Rail` DMN decision table
image::dmn/dmn-execution-expression.png[]

.Example `tTrain` DMN data type
image::dmn/dmn-execution-data-type.png[]

For more information about creating DMN models in {CENTRAL}, see
ifdef::PAM[]
{URL_DEVELOPING_DECISION_SERVICES}#assembly-dmn-models[_{DMN_MODELS}_].
endif::[]
ifdef::JBPM[]
https://docs.jboss.org/drools/release/latestFinal/drools-docs/html_single/#drools.DMN[Decision Model and Notation (DMN)] in the {PRODUCT_DROOLS} documentation.
endif::[]

.Prerequisites
* All required data objects and DMN model components are defined in the project.

.Procedure
. In {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 Train` business process incorporates the DMN service in the `Route To Rail` node:

.Example `Accept Train` business process with a DMN service
image::dmn/dmn-execution-business-process.png[]
--
. Select the business rule task node that you want to use for the DMN service, click *Diagram 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 Rail`

. 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 Rail` DMN service node in this example, you add an input assignment for `Train` that corresponds to the input node in the DMN model, and add an output assignment for `Rail` that 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.

.Example input and output mapping for the `Route To Rail` DMN service node
image::dmn/dmn-execution-io-mapping.png[]
--
. 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 *Diagram properties* -> *Implementation/Execution* -> *On Exit Action* value is set to the following code to store the rail number after the `Route To Rail` DMN service is complete:

.Example code for `On Exit Action`
[source,java]
----
train.setRailNumber(rail);
----
<commit_msg>BXMSDOC-6395: Added a note for Namespace and DMN Model Name fields value to be same (#2796)<commit_after>[id='dmn-execution-business-process']
= Invoking a Decision Model and Notation (DMN) service in a business process

You can use Decision Model and Notation (DMN) to model a decision service graphically in a decision requirements diagram (DRD) in {CENTRAL} and then invoke that DMN service as part of a business process in {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 {CENTRAL} for the routing decision logic:

.Example `Train` object
[source,java,align="center"]
----
public class Train {

     private String departureStation;

     private String destinationStation;

     private BigDecimal railNumber;

     // Getters and setters
}
----

.Example `Compute Rail` DMN model
image::dmn/dmn-execution-graph.png[]

.Example `Rail` DMN decision table
image::dmn/dmn-execution-expression.png[]

.Example `tTrain` DMN data type
image::dmn/dmn-execution-data-type.png[]

For more information about creating DMN models in {CENTRAL}, see
ifdef::PAM[]
{URL_DEVELOPING_DECISION_SERVICES}#assembly-dmn-models[_{DMN_MODELS}_].
endif::[]
ifdef::JBPM[]
https://docs.jboss.org/drools/release/latestFinal/drools-docs/html_single/#drools.DMN[Decision Model and Notation (DMN)] in the {PRODUCT_DROOLS} documentation.
endif::[]

.Prerequisites
* All required data objects and DMN model components are defined in the project.

.Procedure
. In {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 Train` business process incorporates the DMN service in the `Route To Rail` node:

.Example `Accept Train` business process with a DMN service
image::dmn/dmn-execution-business-process.png[]
--
. Select the business rule task node that you want to use for the DMN service, click *Diagram 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 Rail`
+
IMPORTANT: When you explore the root node, ensure that the *Namespace* and *DMN Model Name* fields consist of the same value in BPMN as DMN diagram. 

. 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 Rail` DMN service node in this example, you add an input assignment for `Train` that corresponds to the input node in the DMN model, and add an output assignment for `Rail` that 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.

.Example input and output mapping for the `Route To Rail` DMN service node
image::dmn/dmn-execution-io-mapping.png[]
--
. 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 *Diagram properties* -> *Implementation/Execution* -> *On Exit Action* value is set to the following code to store the rail number after the `Route To Rail` DMN service is complete:

.Example code for `On Exit Action`
[source,java]
----
train.setRailNumber(rail);
----

{'fraction_non_alphanumeric': 0.07840202624913654, 'fraction_numerical': 0.0009210223347916187, 'mean_word_length': 4.512055837563452, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 4, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6964354', 'n_tokens_mistral': 2381, 'n_tokens_neox': 2304, 'n_words': 1187}