jBPM DMN Tutorial – Using Functions in DMN (FEEL Functions Explained)

🚀 Introduction

In jBPM, DMN (Decision Model and Notation) is widely used to model business rules, decision logic, and calculations.
One of the most powerful parts of DMN is the ability to use functions written in:

  • FEEL (Friendly Enough Expression Language)

  • Java (via invocation)

  • External logic (via WorkItemHandlers + DMN inputs)

In this blog, we will focus on the DMN FEEL functions, the most commonly used and the most powerful inside DMN models.


🧩 What is a DMN Function?

A function in DMN is a reusable block of logic that can:

✔ Take inputs
✔ Perform calculations
✔ Return an output

You can call functions inside decision tables, literal expressions, or context entries.

DMN in jBPM supports:

  • Built-in FEEL functions

  • Custom FEEL functions

  • Boxed functions (literal function expressions)


🔵 1. Built-in FEEL Functions

FEEL provides many ready-made functions.

👉 Commonly used DMN FEEL functions:

FunctionPurpose
string(length)Convert values to string
number()Convert text to number
lower() / upper()Convert case
contains(text, substring)Check if substring exists
substring(text, start, length)Extract text
sum(list)Add values in list
min(list) / max(list)Min & max values
today() / now()Date & time
duration()Time difference

🟢 Example: Using Built-in Functions in a Decision Table

🧾 Use Case

Calculate the final price based on discount logic.

📌 Inputs

  • amount

  • discountPercent

📌 Literal Expression using FEEL Function

amount - (amount * discountPercent / 100)

📌 Example in Decision Table

Condition (amount)Condition (discountPercent)Output Expression
> 100010amount - (amount * 0.10)
<= 10005amount - (amount * 0.05)

🟡 2. Custom FEEL Functions

You can define your own functions inside the DMN model.

There are two ways:


🟡 A. Boxed Function (Literal Function)

Example:

Define a function to calculate age based on birth year.

function(birthYear) (year(today()) - birthYear)

You can then call it:

age(1990)

Returns:

34

🟡 B. Named Function (Reusable)

Inside your DMN context, you can define reusable functions.

Example:

{ calculateTax: function(amount, taxPercent) amount * taxPercent / 100, finalAmount: amount + calculateTax(amount, 18) }

You can then use:

calculateTax(1000, 18)

🔴 3. Java Functions Inside DMN (Advanced)

jBPM allows invoking Java classes from DMN using:

  • KIE WorkItemHandlers

  • Java functions exposed to DMN context

  • Custom KieRuntime Extensions

Example Java Method:

public static int doubleValue(int n) { return n * 2; }

You can expose it via:

<import name="myfunctions" type="http://java"/>

And call inside DMN:

myfunctions.doubleValue(5)

📘 Full Example: Discount Calculation Using DMN Function

DMN Function:

function(amount, discount) amount - (amount * discount / 100)

Decision Table Calling the Function:

AmountDiscountResult
>100010calculate(amount, discount)
<=10005calculate(amount, discount)

FEEL Expression:

calculate(amount, discount)

🔗 Linking DMN Function with jBPM Workflow

BPMN Workflow:

Start → Business Rule Task (DMN) → Service Task → End

Business Rule Task Configuration:

  • DMN File: discount.dmn

  • Model name: DiscountModel

  • Decision: FinalPrice

Runtime call from Java:

KieSession ks = kieContainer.newKieSession(); ks.startProcess("discountProcess");

Output variables will include:

{ "finalPrice": 1350 }

📊 Summary Table

FeatureSupported in jBPM DMN?Notes
Built-in FEEL functionsVery commonly used
Custom FEEL functionsBest for business rules
Boxed functionsDMN-standard
Java functions⚠️Advanced integration
Script functionsNot part of DMN standard

👉 Watch “DMN” in Action:

A live demo showing all components of DMN:

🎬 YouTube: Learn IT with Shikha video 1


🎬 YouTube: Learn IT with Shikha video 2

👉 Source code: LearnITWithShikha/DMNExamples



🎯 Conclusion

DMN functions in jBPM allow you to:

✔ Reduce complexity
✔ Reuse logic
✔ Make business rules clean and maintainable
✔ Share logic across multiple decision tables
✔ Implement FEEL and Java-based functions

DMN + FEEL functions = powerful, clean, and highly reusable decision logic.

If your decision logic repeats across your rules, ALWAYS convert it into a DMN function.

 

💼 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