dmnredhat-bpmfeel-language

Handling null when returning through Business Knowledge model in DMN


I am trying to make some Business rules using DMN on kie Server.

There I have structure data object and its list which is my input. I am using rule to validate my structure list and get only those who passes my condition.

I am using BusinessKnowledgeModel which has actual condition for each object and I have decision logic which iterated through my list and calls the BusinessKnowledgeModel function.

Decision Iterator Feel language code:

for inputParam in InputList return BusinessKnowledgeModel(inputParam)

In the BusinessKnowledgeMode, I have my function which consists of decision table that checks my condition through Feels expression.

Instead of getting null as otput from function, I just want to skip it.

My efforts:

I did try to explore trying to find various approaches; like finding if continue keyword can be used in for loop. Even tried adding constraint on Data objects, but not null constraint can't be added on Structures.


Solution

  • There is no equivalent of continue; operator which is typical in procedural languages as FEEL is an expression language. The closes analogy you can draw if you are familiar with say, Java, is that you need something equivalent of what you could do with the JDK Stream, e.g.: filtering in this case sounds appropriate.

    It is likely you can achieve what you need by having your expression filtered:

    (for inputParam in InputList return BusinessKnowledgeModel(inputParam))[item!=null]
    

    Demonstration

    In this example DMN model I have inputList as a list of numbers, and bkm() is a function returning the same number if it's divisible by 2, otherwise null:

    if (modulo(p1, 2) = 0) then p1 else null
    

    The Decision-1 node: decision node is filtering from the returned list of the for, only the numeric element, as you can see input list size is 10 element, Decision-1 list size is only 5 element, filtered out of the nulls

    The complete example: the complete example

    please notice the output column shows the list elements with indexing, element index 0 is the value 2, element index 1 is the value 4, etc.