0

I have bpmn2 file in which I use as a process data POJO application. To learn how to work with DMN I wanted to change 1 POJO property depending on smth inside the DMN. I manged to make DMN working when on the input I had application and on the output I had a string value. Now I want to hade in the input application on the input and modified application on the output: DMN Data I\O

Inside DMN I have the following structure:

DMN Structure

I have created data type tApplication with string algId field: DMN data type

So the aplication inside DMN is a tApplication data type, for decision I tried to use the decision table:

DMN Decision Table

My idea was- when application.algId == "101" change that value to "115", but for the input

{
  "application": {
    "algId":"101",
    ...
  }
}

I get following results:

{
    "id": "98b8a9ad-1c1d-4c4f-8525-6e5fe9a528c9",
    "application": {
        "algId":"101",
    ...
  }
}

What am I doing wrong? What is the best practice to change the POJO object inside the DMN?

Donvino
  • 2,407
  • 3
  • 25
  • 34

1 Answers1

2

A very relevant and similar use-case was described precisely in:

before accessing the code, I would strongly recommend to watch the video or read the blog post first.

It is important to remind that the DMN Specification mandates for a stateless and side-effect free model, so you can't mutate an existing InputData variable, per-se. However, you can make use of "data enrichment" strategies to fulfil your use-case, per the blog post and video.

There are 2 main strategies you could follow, in short:

  • in the DMN model, you decide for the algId as its own Decision node named algId which later will be used in BPMN process Data I/O in order to update the process variable of type Application with the expected result
  • in the DMN model, you come up with a data enriched final decision which has the same structure of Application type, using the new DMN FEEL built-in such as context put() and you replace the process variable with that decision
tarilabs
  • 2,178
  • 2
  • 15
  • 23
  • Usually we enreach the input data with new fileds, f.e. we have requested tag and we add some data to calcualted tag, so as I can see DMN is not and option for us - leaving drl for rulles and java functions for data preparation. – Donvino May 05 '22 at 08:42
  • 1
    @Donvino no I don't think so at all. The new `context put()` built-in function of DMN are purposely build for that use case, to enrich. Then in the BPMN process you set the process variable to the decision result, which is the enriched structure. Per the blog post. – tarilabs May 05 '22 at 09:16
  • To be clear: I have the following structure Application.terms.requested.limit and Application.terms.requested.rate depending on those 2 values I want to put some value in Application.terms.calculated.limit, Application.terms.calculated.rate and Application.decision. Would it be o.k. to use context put()? Is there an example for more complex context put() than for 1-level json object? – Donvino May 05 '22 at 09:54
  • 1
    A1. Yes, it was designed in the DMN spec to accept also a nesting use case. A2. for example `context put( Incoming Application, [ "terms", "calculated", "limit"], )`, and equivalently for the other. You should also chain them to apply first to the `limit` and then to the `rate`, and then to the `decision`, you could use multiple Decision node or Boxed Context per standard DMN practices for that. – tarilabs May 05 '22 at 10:29
  • Error compiling FEEL expression 'context put(Request, ["terms", "creditParameters", "calculated" , "loan" ,"rate"], Determine Final Rate)' for name 'Processed Request' on node 'Processed Request': syntax error near 'put' - do I need to add some dependency in pom file? – Donvino May 05 '22 at 13:10
  • 1
    You're likely not using the latest version of kie-dmn-core from Drools DMN Engine or the latest from Kogito DMN. It should work out of the box using latest Kogito version. Please ensure you are using a recent version? Otherwise feel free to engage on the kogito mailing-list and sharing your reproducer there; you can find the links to the mailing-list here: https://kogito.kie.org/community/ – tarilabs May 05 '22 at 14:19