Camunda 7 DMN – Complete Guide with Examples

 https://docs.camunda.org/get-started/dmn/img/modeler-save-dmn-table.png?utm_source=chatgpt.com

DMN (Decision Model and Notation) is a powerful standard used in Camunda 7 to automate decisions using Decision Tables, Context, Literal Expressions, and FEEL.

It separates business logic from workflow logic, making your BPMN processes cleaner, maintainable, and business friendly.

In this guide, you will learn how to create, deploy, and execute DMN tables in Camunda 7 using Java, REST, and Modeler.


What is DMN?

DMN = Decision Model and Notation
Created to:

✔ Automate business rules
✔ Externalize decision logic
✔ Allow business users to define rules
✔ Integrate with BPMN processes
✔ Support FEEL expressions (Friendly Enough Expression Language)

In Camunda, DMN is executed by the Decision Engine, which is part of the Camunda BPM platform.


1️⃣ Creating a DMN Decision Table in Camunda Modeler


A DMN table contains:

  • Inputs (values coming from the process or API)

  • Rules

  • Outputs (result of evaluation)

  • Hit Policy

  • FEEL expressions

Example Scenario

Loan Approval decision based on:

  • Credit score

  • Monthly income

  • Loan amount

Sample DMN Table

Credit ScoreIncomeLoan AmountResult
> 700> 50000< 10,00,000APPROVE
600–700> 40000< 5,00,000REVIEW
< 600anyanyREJECT

2️⃣ Understanding Hit Policies


Hit PolicyMeaning
U – UniqueOnly one rule must match
F – FirstFirst matching rule wins
A – AnyAny matching rule may be returned
C – CollectReturns list (sum, min, max, count)
P – PriorityHighest priority rule wins
R – Rule OrderRules returned in order
O – Output OrderSorted by output priority


Most common: Unique (U) and First (F).


3️⃣ FEEL Expressions

FEEL is used inside DMN for conditions.

Examples:

ExpressionMeaning
> 500Value greater than 500
[10..20]Between 10 and 20
<= 1000Less than or equal to 1000
"Gold"Matches string Gold
not("India")Not India
nullEmpty value

4️⃣ Deploying a DMN Table

Place DMN file under:

src/main/resources/decisionTables/

Camunda auto-deploys DMN files from resources folder.


5️⃣ Calling DMN from BPMN


Add a Business Rule Task → set implementation:

Decision Ref = loan_decision
Result Variable = loanResult
Map decision inputs via input mappings
Use FEEL or script expressions

Example variable mapping:

InputDMN Input
${creditScore}creditScore
${income}income
${amount}loanAmount

6️⃣ Execute DMN from Java

@Autowired DecisionService decisionService; public void evaluate() { VariableMap variables = Variables.createVariables() .putValue("creditScore", 720) .putValue("income", 60000) .putValue("loanAmount", 800000); DmnDecisionTableResult result = decisionService.evaluateDecisionTableByKey("loan_decision", variables); System.out.println(result.getSingleResult().getEntry("Result")); }

7️⃣ Execute DMN via REST API

POST http://localhost:8080/engine-rest/decision-definition/key/loan_decision/evaluate { "variables": { "creditScore": {"value": 720}, "income": {"value": 60000}, "loanAmount": {"value": 800000} } }

8️⃣ DMN with Spring Boot

Add dependency:

<dependency> <groupId>org.camunda.bpm.springboot</groupId> <artifactId>camunda-bpm-spring-boot-starter</artifactId> <version>7.21.0</version> </dependency>

Place DMN under:

src/main/resources/dmn/

Call using DecisionService as shown above.


9️⃣ Real-World Example: Credit Risk Classification























Inputs:

  • Past defaults

  • Age

  • Salary

  • Country

  • Account balance

DMN outputs:

  • HIGH_RISK

  • MEDIUM_RISK

  • LOW_RISK

This plugs directly into your BPMN workflow for automated decision routing.


🔟 Best Practices for DMN in Camunda 7

✔ Use FEEL for business-friendly logic
✔ Avoid script expressions when FEEL is enough
✔ Use Unique hit policy when rules must not overlap
✔ Use Priority hit policy for risk-based scoring
✔ Keep DMN tables small & simple
✔ Use meaningful column names
✔ Always set Result Variable when used in BPMN
✔ Store DMN models in a separate folder
✔ Add unit tests for rule validation


📌 Common Mistakes to Avoid

❌ Using Java delegates instead of DMN
❌ Missing decisionRef in Business Rule Task
❌ Wrong variable name mapping
❌ Overlapping rules without correct hit policy
❌ Using scripts instead of FEEL
❌ Hardcoding DMN values in BPMN


Rest APIs

https://docs.camunda.org/rest/camunda-bpm-platform/7.23/#tag/Decision-Definition/operation/evaluateDecisionByKey


🎉 Conclusion

DMN in Camunda 7 gives you:

✔ Clean separation between workflow and decision logic
✔ High-performance automated rules engine
✔ Business-friendly FEEL rule definitions
✔ Easy integration with Java, REST, Spring Boot
✔ Clear and maintainable decision logic

DMN makes your processes faster, smarter, and easier to maintain — a must-learn feature for every Camunda developer.


💼 Professional Support Available

If you are facing issues in real projects related to enterprise backend development or workflow automation, I provide paid consulting, production debugging, project support, and focused trainings.

Technologies covered include Java, Spring Boot, PL/SQL, Azure, and workflow automation (jBPM, Camunda BPM, RHPAM).


Comments

Popular posts from this blog

jBPM Installation Guide: Step by Step Setup

Scopes of Signal in jBPM

OOPs Concepts in Java | English | Object Oriented Programming Explained