DMN Functions in jBPM

 💡 Introduction

In jBPM, we often use DMN Decision Tables to define rules visually.
But sometimes, the same logic (for calculations, validations, or text manipulation) is needed across multiple rules.
Instead of repeating that logic, you can define it once as a 📦 Function inside DMN and reuse it in your Decision Tables, Literal Expressions, or Contexts.

This makes your decision models more modular, maintainable, and business-friendly.


🧠 1️⃣ What Is a Function in DMN?

In DMN, a function is a reusable piece of logic written in FEEL (Friendly Enough Expression Language).
It can accept input parameters and return values just like a normal programming function.

✅ Example of a simple FEEL function:

function(x) x * 2

📊 You can define it:

  • Inside a Context

  • As a separate Decision node

  • Or as a Business Knowledge Model (BKM) for global reuse


⚙️ 2️⃣ Why Use Functions in DMN

ReasonBenefit
🧾 ReusabilityDefine once, use across multiple decisions
⚙️ MaintainabilityUpdate logic in one place only
🔍 ClarityKeeps decision tables cleaner
🚀 PerformanceFEEL functions are lightweight and fast

🧩 3️⃣ Example Scenario

Let’s say we want to evaluate employee bonuses based on salary and performance rating.

We’ll create:

  • A function to calculate the base bonus

  • A decision table to decide the final bonus category


🧱 4️⃣ Step-by-Step: Create Function in DMN

🧮 Step 1: Define Function Node

In Business Central → Design → Create → DMN,
add a Business Knowledge Model (BKM) or Decision Node named CalculateBonus.

Inside its boxed expression, define:

function(salary, rating) if rating = "A" then salary * 0.2 else if rating = "B" then salary * 0.1 else salary * 0.05

This function takes two inputs (salary and rating) and returns the computed bonus.


🧩 5️⃣ Step 2: Create Decision Table That Uses the Function

Now, create another Decision node named BonusDecision.

Input Data:

  • salary

  • rating

Decision Table Configuration:

RatingBonusDescription
"A"CalculateBonus(salary, rating)"Excellent"
"B"CalculateBonus(salary, rating)"Good"
"C"CalculateBonus(salary, rating)"Average"

FEEL Expression Example:

CalculateBonus(salary, rating)

🎯 This directly calls the previously defined function node!


🧩 6️⃣ Step 3: DMN Context Example (Alternate Way)

If you prefer defining functions inline within a context:

{ CalculateBonus: function(salary, rating) if rating = "A" then salary * 0.2 else if rating = "B" then salary * 0.1 else salary * 0.05, FinalResult: CalculateBonus(salary, rating) }

✅ In this example, the FinalResult uses the CalculateBonus function directly.


💻 7️⃣ Step 4: Call DMN from jBPM or Java

You can now invoke the DMN model in your process flow or Java code.

Java Example:

KieServices ks = KieServices.Factory.get(); KieContainer kContainer = ks.getKieClasspathContainer(); KieSession kSession = kContainer.newKieSession(); DMNRuntime dmnRuntime = KieRuntimeFactory.of(kSession).get(DMNRuntime.class); DMNModel model = dmnRuntime.getModel("http://example.com/dmn", "BonusModel"); DMNContext context = dmnRuntime.newContext(); context.set("salary", 80000); context.set("rating", "A"); DMNResult result = dmnRuntime.evaluateAll(model, context); System.out.println("🎯 Bonus: " + result.getContext().get("BonusDecision"));

Output Example:

🎯 Bonus: 16000.0

🧠 8️⃣ Using Functions Across Multiple Decisions

Once defined, your function (like CalculateBonus) can be reused in:

  • Decision Tables

  • Literal Expressions

  • Other Functions

  • FEEL conditions

For example:

if CalculateBonus(salary, rating) > 10000 then "High Bonus" else "Low Bonus"

🧰 9️⃣ Troubleshooting Tips

IssueCauseSolution
Function not foundFunction not linked or importedEnsure decision or BKM is connected to the dependent node
⚠️ Null valueInput variables not mappedVerify salary and rating are correctly passed
🧮 Wrong calculationFEEL syntax issueUse Preview DMN XML to confirm function definition

🧩 🔟 Example DMN XML Snippet

<dmn:decision id="CalculateBonus" name="CalculateBonus"> <dmn:variable name="CalculateBonus" typeRef="number"/> <dmn:literalExpression> <dmn:text> function(salary, rating) if rating = "A" then salary * 0.2 else if rating = "B" then salary * 0.1 else salary * 0.05 </dmn:text> </dmn:literalExpression> </dmn:decision>

Then, in your decision table:

<dmn:outputEntry> <dmn:text>CalculateBonus(salary, rating)</dmn:text> </dmn:outputEntry>

👉 Watch "Create Function in DMN and Use It in Decision Table" in Action:

Here’s a short demo video to help you understand how to call functions inside DMN tables in jBPM: 
 YouTube: Learn IT with Shikha



🏁 Conclusion

🚀 DMN functions in jBPM allow you to modularize and reuse logic across decision tables.
They make your decision models cleaner, faster, and easier to maintain.

By combining BPMN (process) and DMN (decision) — with reusable FEEL functions —
you bring both intelligence 💡 and flexibility 🔄 to your business automation.

💼 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).  

📧 Contact: ishikhanirankari@gmail.com | info@realtechnologiesindia.com

🌐 Website: IT Trainings | Digital metal podium  




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