Multi-Instance completionCondition

I have been testing around the Multi-Instance for a Call Activity and in parallel and I am now facing troubles with using predefined variables in the completionCondition. I have tried
loopCounter = 2
that works fine for the flow.
When I try anything with numberOfInstances, numberOfActiveInstances, numberOfCompletedInstances, numberOfTerminatedInstances, I get this kind of error:

failed to evaluate expression 'numberOfInstances = 2': no variable found for name 'numberOfInstances'

Am I missing something here to understand? Am I supposed to declare these variables somewhere?

Hey @creative,
I am happy to take a look at this!

It looks like there is no variable in the context with the name “numberOfInstances” available. Keep in mind that these are not “predefined” and available by default.
You would always need to have them explicitly available in the process instance.

Is this the case for you?

Ah I see! I am using java for the Handler and Definition of processes. I did not know these weren’t predefined like loopCounter for example. Do I simply need to declare them to be able to use them? For example:
public static final String WORKER_TYPE = "WORKER_NAME";
Or do I need to have a method for it?

So either you create this variable on startup at the process or you can create one during the runtime using a worker.

This would look something like this:

JobWorker(type = "foo")
public Map<String, Object> handleJobFoo(final ActivatedJob job) {
  // some work
  if (successful) {
    // some data is returned to be stored as process variable
    return variablesMap;
  } else {
   // problem shall be indicated to the process:
   throw new ZeebeBpmnError("DOESNT_WORK", "This does not work because...");

Long story short: Either start the process with this value, or set it using a “worker” method. :slight_smile:
Hopefully this was hepful to you!


But I thought these variables were available by default as mentioned here: Multi-instance | Camunda Platform 8 Docs

The BPMN 2.0 specification defines the following properties of a multi-instance body:

  • numberOfInstances: The number of instances created.
  • numberOfActiveInstances: The number of instances currently active.
  • numberOfCompletedInstances: The number of instances already completed.
  • numberOfTerminatedInstances: The number of instances already terminated.

But somehow none of these values work as I get the error mentioned previously.

So I need to declare them in the JobWorker or at the startup process?

Hmm that is interesting :thinking:
I haven’t used these properties in my complete conditions yet.
Have you tried running the exact expression as in the docu once?

I tried this:
numberOfCompletedInstances / numberOfInstances >= 0.5
and it did not give me an error but it also just went through every item in the collection and completed them. It didn’t terminate any of them.

Puh… maybe it is a bug(?) - or I am missing something as well.
I will try to find someone who can add some clarification. :+1:

In the meantime I can only recomment initializing these variables before. That will work for sure :smiley:

P.S.: maybe you could share your BPMN file so I can try it out myself.

Hi @creative :wave: I’d also be interested to see your process model (bpmn file). Did you happen to use these properties in the completionCondition expression, or in another place? And which version of camunda 8 are you using? These properties are introduced only to the completionCondition, and only since version 8.1.


This sounds like it could be a bug. Can you provide a reproducible example?

Unfortunately I cannot provide the actual bpmn file as it is work related.
The call activity with the Multi-instance is this way:
And it calls a flow that each inputElement need to go through.

We use Camunda Platform 8.0 So Maybe the version is the issue?

And I only used the variables in the completionCondition:

We use Camunda Platform 8.0 So Maybe the version is the issue?

You’ll need to upgrade to version 8.1 to have access to the multi-instance properties in the completion condition expression. Please let me know if that solves your issue :slight_smile:

Will do that, thank you!

You’ll also need to change Completion condition to numberOfCompletedInstances / numberOfInstances >= 0.5 to try this out. These properties are only available to the completion condition expression. They are not available as variables, nor as input/output mappings.