Call different subprocess based on variable and go back to main process

Hi Camunda Community,

Instead of having a gateway with N outgoing branches, I would like to delegate the work to subprocesses based on some input variable. For example, if my input_var="message_A", then the subprocess subscribing to message_A is started, then, once it is finished, it goes back to the main process, passing some variables generated in the subprocess to the main process. See the screenshot below:

Doing the above doesn’t work as I have the following error:

The process could not be started. : Cannot instantiate process definition master:1:f75a21cf-0f9e-11ea-89b8-50eb7136ed6c: Error while evaluating expression: ${execution.getProcessEngineServices().getRuntimeService().createMessageCorrelation(“message_A”).correlateWithResult()}. Cause: org.camunda.bpm.engine.MismatchingMessageCorrelationException: Cannot correlate message ‘message_A’: No process definition or execution matches the parameters

Any idea why it doesn’t work? It this even a good approach? Thanks a lot for your upcoming feedbacks.

my bpmn file:
master.bpmn (8.6 KB)

The BPMN standard doesn’t let you send a message that does not leave the scope of the process which creates it. Which is probably for the best because you should probably be using a conditional event rather than a message event, it’ll do what you want with a lot less effort.

Thanks @Niall for the reply, so, in general, the best way to replace a gateway with N outgoing branches (a bit ugly I suppose) is then to use a conditionnal event subprocess. Variables created in that subprocess will be sent back to the main process right ?

If there a specific reason why you want to replace the gateway in the first place?

The reason is that each subprocess is associated to a specific decision table. The decision tables are very specific and depend on a variable defined in the main process (different types of json objects and 1 json object = 1 table). The keys in my json object might change and I need to adapt my tables in consequence. The thing is that I’ll probably need to deal with dozen of json objects (i.e dozen of decision tables), having subprocesses instead of multiple branches is probably more human readable.

In other words, using a scripting philosophy, I just want to call different functions based on the input variable value (the functions being the subprocesses in this analogy).
y=f(x=a) or y=g(x=b)

Can’t you just use an expression to call the DMN table you want dynamically?

I would love to do it this way, but I’m still a unexperienced camunda user and an example would greatly help. What do you mean by calling a DMN table dynamically?

If you are using a Business Rule Task the decisionRef can be a variable expression so you could set the name of the DMN table as a variable.

1 Like

Thinking of it I suppose you could have a expression returning the DMN name based on that other variable you had.

Thanks a lot @Niall and @JarlSeverin, it works like a charm, I made the decision based on my variable, I guess it’s not quite the answer to my original questions but it serves very well my purpose. Hope it can help someone else. Here an example of what I’m using right now:

The ${dmn_table}${"_choice"} redirects to the desired table.

For info for new camunda user: You can modify the variable in the task listener if a simple string concatenation is not enough to choose on the table

1 Like