Send messages in multitask, depending on DMN output

Hi Camunda users,

I have several BPM diagrams written in seperate files and I’m using “message” events to start the associated processes. The process(es) that need(s) to be started depend(s) on the result of a Business rule task.

Example: If my DMN input is “key_1” then two processes should be started, one process that is launched with a “message” start event containing “out_1” and a second process that is launched with message “out_2”.

I use a multitask subprocess philisophy to loop over “out_1” and “out_2”. Here is the simple image of my diagram:

I read this:

But it’s not based on the output of a decision table. So my questions are:

How can I define in my DMN a single output that is an array?
How can I loop over this array in my multitask process?

Please let me know if you have any idea, I’m stuck with this one…thanks

ch.

Hi Chris, Have you read over this one? Pattern Review: DMN Looping for Array Input

Hi @StephenOTT,

Thanks for your quick reply. I checked your proposed solution, which is indeed really nice to append elements to a json variable when combining multi-instance and DMN tasks. However, my case is slightly different from yours in the way that my output is a fixed array, it shouldn’t grow by appending elements in values like in your combinedResult json.

In my case, a single output should be the json variable, something like:
S('{"values":["out_A","out_B"]}')

Then, from there, I could use your solution to send messages using multi-instance on json collection.
However when deploying my table and running the instance I get the following message from the cockpit:
The process could not be started. : Cannot instantiate process definition master_loop:13:4c49532c-0539-11ea-bdca-50eb7136ed6c: Cannot serialize object in variable 'decisionResult': org.camunda.spin.impl.json.jackson.JacksonJsonNode

My question should be then, can I output a JSON variable containing my array directly from my DMN without using multi-instance?
(NB: creating an empty JSON output before the DMN and looping over DMN task to feed array sounds overly complex for that simple purpose)

Hope the community can help me with that.

Here are my DMN and BPMN files:
master_loop.bpmn (3.7 KB) decide_out.dmn (1.7 KB)

A multi instance just requires a java collection. So the output of the dmn that generates a array should be a collection. Then just pass that collection as the elements for your multiinstance

Yes you’re right @StephenOTT, but the challenge is to create the collection in the DMN table without using a multi-instance (as a collection type is not supported in the DMN). So I use string.split(",") in my DMN listener to create this array but then I get:
Cannot serialize object in variable 'array': SPIN/DOM-XML-01030 Cannot create context

Something might be wrong in my inline script but I don’t get it…
var str=execution.getVariable("dmn_output") var array=str.split(",") execution.setVariable("array",array)

My DMN output is a single string, for example, “out_A,out_B”

master_loop.bpmn (5.7 KB)
decide_out.dmn (1.9 KB)

@ChrisB you cannot use the Collect Hit policy to create a java collection from the DMN result?

https://docs.camunda.org/manual/7.7/reference/dmn11/decision-table/hit-policy/#collect-hit-policy

Hi @StephenOTT,

It works perfectly now with the collect hit policy approach, thanks a lot for your time and concern. Here is in my illustrated example and the associated BPMN and DMN files.

master_loop.bpmn (5.5 KB)
decide_out.dmn (1.9 KB)