Local Variable Scopes in Multi-instance (external) service tasks

Hi all,

Using Camunda 7.15.
This specific Service Task will be handled entirely by API Rest, so no Java solutions.

What I am trying to achieve: Start a multi-instance activity of type Service Task. The variables (local+global) from each instance have to be both accessible during the Fetch&Lock AND during “any-time” (ie: using /engine-rest/variable-instance/..).

What I achieved so far:

  • Process .bpmn has been designed and deployed.
  • The process definition can be started.
  • I can create processes instances for it.
  • The “multi” part of instances is working (ie: I can create N parallel tasks, each with their own item from the InputCollection).
  • I can see all (local+global) variables during Fetch&Lock, but I am not able to re-visit the variables using any other API.

Problem: I noticed the LocalVariables (even the “default” ones: loopCounter and the item (from InputCollection)) have a totally different executionId vs the expected (?) executionId which would be from each parallel sub-task instance. With that, I am not able to use the Variable Filter because I can not differentiate which variable belongs to which instance.

In hope of putting it into words in a digestible way.
Imagine a process-instance with 2 parallel instances inside an Multi-Instance activity. The process-instance has a variable on its scope "number": 42. The InputCollection is ["aaa", "bbb"] and there are no localVariables for each parallel subtask.

Doing a GET to engine-rest/process-instance/{id}/activity-instances, I get the following tree:

  • 01 executionId for the process instance (lets call this PIID)
  • Inside of it, 03 executionIds for the multiInstanceBody (lets call these MIB, T1, T2)
  • Inside the multiInstanceBody, the are 02 children (one for each parallel subtask), each with their own executionId (lets call these PST1, PST2*)

– Process Instance –
If I check for variables processId = PIID, I can see number=42; OK so far,

– Multi Instance Body –
I assume MIB is the “legit” executionId for the multiInstanceBody, since it has the 03 “special” variables (nrOfInstances, nrOfCompletedInstances, nrOfActiveInstances)
Here comes the weird part: Both T1 and T2 have the LocalVariables from the “parallelization”

  • T1 has loopCounter=0, item="aaa"
  • T2 has loopCounter=1, item="bbb"

– Parallel (sub) Service Task –
Both PST1 and PST2 retrieves no LOCAL variables attached to them (which is expected, since no variables were initialized on their scope).

And, here is the problem: I have no easy way to co-relate 1:1 the executionIds T1, T2 from the multiInstanceBody with the executionIds PST1, PST2 from the children. Filtering for ActivityInstancesIn (and supplying each sub-task’s own activityInstanceId) also returns no variables (local or global).

Worth to say that this DOES NOT happen when dealing with User Tasks — For this very same scenario, the multiInstanceBody would only have 01 executionId and each child parallel subtask would have the LocalVariables (loopCounter, item) within their executionId scope. Filtering variables for EITHER activityInstancesIn=[subtaskN...] or executionIdIn=[subtaskN] would work perfectly.

What gives? Am I misunderstanding the feature or usage of the process-engine, or is this some weird behaviour caused by something silly for this use case?

Thank you very much in advance.


Not that this will help, but there’s a hint in the name… ExecutionID
Each UserTask will end up in its own Execution because by definition they are async.
Script Tasks and sync service tasks don’t necessarily get their own Execution.

However in the C7 world, you can find all the pieces that belong to a particular instance by using business keys…

Hi, first of all, thanks for your time reading & replying
Unfortunately I don’t see know businesses keys help me (since it would replace a process-intance-id to many sub-tasks).

About “Script Tasks and sync service tasks don’t necessarily get their own Execution.”, I am sure the parallel subtasks DO have their own executionId (as can be seen in first pic/json, lines 29 and 50).

Although, I found a new hint about something that helps me relating these two entities, albeit I do not know (yet?) how to access this info through the API.

The new hint is: in the ACT_RU_EXECUTION table, I can see that a ID_ does have a parent PARENT_ID_ (and that perfectly links the two entities, as per json, lines: 29 & 64). That is EXACTLY what I need, since knowing the parent is enough for me to use GET \variable-instances\ on the parent and then retrieve the variables as needed/anytime.

Thank you again for the discussion!

I’ve found another thread of a guy having the same issue (Multiple Instance: How to obtain LoopCounter in External tasks?). Linking it here since he worded his thread is way fewer words.

I am not going to revive that thread (as its from `19), but that shows this issue hasn’t affected just me.

Is there really nothing to be done? I am willing to accept “janky” solutions if that is the case, using User Tasks for my use case would bring way more complications than whatnot.