DMN Custom functions

Hi Guys,

Couldn’t find much information on this. Hope you can help.

Is it possible to use custom functions in Input Expressions & Values? Say: Math.ceil, String.indexOf, (or) Custom functions like MyClass.method.

It would be great if you can point me to an example demonstrating this.

Thanks
-Bharat

You should be able to call any static function of any class using the fully qualified class name of the class and the method name. This should work: ${ java.lang.Math.ceil(...) }

If you want to make that available as ${ ceil(...) } you need to implement a custom function mapper. This is a little bit more complicated but we can give you the pointers

Note that at some point it gets easier to write a Groovy Script or Java Script as input expression

Morning Daniel,

It’s good to know that we can use fully qualified name of the class for this kind of needs. And understand that Groovy/JS could do much powerful job.

Looking from analyst point of view Custom Functions may look little less confusing in some cases. Is there any GitHub example/test case that you can point me to on this please.

I fully agree. @Ingo_Richtsmeier @BerndRuecker You guys built an example for custom function mapper in dmn, correct? Is it publicly available?

It is available - but actually undocumented at the moment: https://github.com/camunda/camunda-consulting/tree/master/snippets/dmn-collection-contains. We have built a process engine plugin registering a new function - it is actually very easy to do.

Cheers
Bernd

Hi Bharat,

have a look at this example how to register a custom function for decision evaluation:

https://github.com/camunda/camunda-consulting/tree/master/snippets/dmn-decision-chaining

Cheers, Ingo

Appreciate your quick response. Thanks team.

@DanielMeyer I just tried this in an output field: ${java.lang.Math.ceil(billing.consumption)}
and it gives a exception: javax.el.PropertyNotFoundException: Cannot resolve identifier ‘java’

It’d be nice to get this working…

Another simple approach is to wrap methods in an object you pass along as variable. It can be accessed like “func.min(billing.amount, 10)” , where “func” is the name of the instance of this class:

public class Functions {
public int min(int a, int b) {
return Math.min(a, b);
}
}

The advantage of this approach or the custom function mapper over the ${java.lang…} approach is that you can limit the diversity of function calls for some all too creative BA’s.

I wonder why java.lang… didn’t work?

for example, ${‘test’.format(‘x=%d’, 2)} works, but ${java.lang.String.format(…)} doesn’t.

That is because you are using Jakarta Expression Language and in particular the JUEL implementation and that standard does not define this interaction with static Java methods.