Cannot use multi instance "element variable" in node input via expressions

Hey,

engine fails to resolve the element variable in a multi instance node (specifically tried using the collection var) with an error that the variable does not exist (by expression)

This seem to be a bug as the variable element can be accessed through the execution runtime,

Thanks,

Asaf.

1 Like

Hi @Asaf_Shakarzy,

can you please share your example?

Best regards,
Philipp

Sure,

Test sample:

@Deployment(resources = "test_processes/multiNode.bpmn")
@Test
public void asserted() throws Exception {
  RuntimeService runtimeService = engineRule.getRuntimeService();
  List<String> col = new ArrayList<>();
  col.add("foo");
  col.add("bar");
  Map<String, Object> initialVars = new HashMap<>();
  initialVars.put("col", col);
    ProcessInstance process = runtimeService.startProcessInstanceByKey("multiNode", initialVars);
  }

Flow sample:

<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" id="Definitions_1" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="1.16.2">
  <bpmn:process id="multiNode" isExecutable="true">
    <bpmn:startEvent id="StartEvent_1">
      <bpmn:outgoing>SequenceFlow_0au0aay</bpmn:outgoing>
    </bpmn:startEvent>
    <bpmn:sequenceFlow id="SequenceFlow_0au0aay" sourceRef="StartEvent_1" targetRef="serviceTask_getAndStorePersonAttrs" />
    <bpmn:endEvent id="EndEvent_1alfi1x">
      <bpmn:incoming>SequenceFlow_0zu5yj0</bpmn:incoming>
    </bpmn:endEvent>
    <bpmn:sequenceFlow id="SequenceFlow_0zu5yj0" sourceRef="serviceTask_getAndStorePersonAttrs" targetRef="EndEvent_1alfi1x" />
    <bpmn:serviceTask id="serviceTask_getAndStorePersonAttrs" name="Multi Node" camunda:class="someNode">
      <bpmn:extensionElements>
        <camunda:inputOutput>
          <camunda:inputParameter name="this">${curr}</camunda:inputParameter>
        </camunda:inputOutput>
      </bpmn:extensionElements>
      <bpmn:incoming>SequenceFlow_0au0aay</bpmn:incoming>
      <bpmn:outgoing>SequenceFlow_0zu5yj0</bpmn:outgoing>
      <bpmn:multiInstanceLoopCharacteristics isSequential="true" camunda:collection="${col}" camunda:elementVariable="curr" />
    </bpmn:serviceTask>
  </bpmn:process>
</bpmn:definitions>

Test execution causes:

Caused by: org.camunda.bpm.engine.impl.javax.el.PropertyNotFoundException: Cannot resolve identifier 'curr'

Hi @Asaf_Shakarzy,

I can reproduce the issue. Good catch :+1:

The element variable is not available in the input variable mapping. To solve the issue, you need to embed the service task into a multi-instance sub-process.

Best regards,
Philipp

Hey,

a multi-instance sub process is way more verbose than a multi-instance task,
Probably the EL expressions are evaluated prior to the set of the element variable.

Should I file a bug about this?

Thanks.

Yes, it seems so.

Feel free the create a new issue.

Done, thanks!

Is there a work-around for this? Even I am facing the same issue, I want to iterate over a list in a service task via multi instance.

I have the same problem and the reported issue is still open. Is there a work-around for this?