AnsweredAssumed Answered

Problem with multi instance workflow

Question asked by babjikundateeri on Aug 29, 2016
Latest reply on Aug 29, 2016 by babjikundateeri
Hi,
I am new to activiti. It might be a silly question.

Please find below my process definition

<blockcode>
  <process id="TestMultiInstance" name="TestMultiInstance" isExecutable="true">
    <startEvent id="startEvent1"/>
    <sequenceFlow id="sid-6186FC5D-9FC7-4A36-948B-36C914A69AB8" sourceRef="startEvent1" targetRef="sid-39AAD947-3626-4B45-8DCF-4D07636B76B1"/>
    <serviceTask id="sid-39AAD947-3626-4B45-8DCF-4D07636B76B1" name="Contact Picker" activiti:delegateExpression="${contactPickerTaskDelegation}">
      <extensionElements>
        <activiti:field name="contactPickerRuleId">
          <activiti:string><![CDATA[7]]></activiti:string>
        </activiti:field>
      </extensionElements>
    </serviceTask>
    <subProcess id="sid-DEA02220-00E9-44E6-B5D2-0A81B5E891F3" name="subProcess" activiti:async="true" activiti:exclusive="false">
      <multiInstanceLoopCharacteristics isSequential="true" activiti:collection="contacts" activiti:elementVariable="contact"/>
      <startEvent id="sid-BE04B538-3E57-4208-87A4-DC66E69674F8"/>
      <serviceTask id="sid-BBD8C2E2-2EAD-4106-85A6-C95B9E649EF3" name="Email" activiti:delegateExpression="${fealtiEmailTaskDelegation}">
        <extensionElements>
          <activiti:field name="emailTemplateId">
            <activiti:string><![CDATA[30003]]></activiti:string>
          </activiti:field>
        </extensionElements>
      </serviceTask>
      <endEvent id="sid-C2CC2D3B-D9DB-486F-8D22-F9BFDB09F228"/>
      <sequenceFlow id="sid-81DF9E03-34D3-4482-82E5-926067174ED8" sourceRef="sid-BE04B538-3E57-4208-87A4-DC66E69674F8" targetRef="sid-BBD8C2E2-2EAD-4106-85A6-C95B9E649EF3"/>
      <sequenceFlow id="sid-52C2E732-AA74-4229-AB8B-95A54BF7A674" sourceRef="sid-BBD8C2E2-2EAD-4106-85A6-C95B9E649EF3" targetRef="sid-C2CC2D3B-D9DB-486F-8D22-F9BFDB09F228"/>
    </subProcess>
</blockcode>

  In the first service task, I am setting the variable into the execution like

<blockcode>
execution.setVariable("contacts", contacts);
</blockcode>

After that SubProcess also creating multiple instances based on size of collection contacts.
after all the instances completed their tasks finally i am having an exception as below

2016-08-29 10:20:36 [FealtiEventSystem-akka.actor.default-dispatcher-5] DEBUG o.a.e.i.interceptor.CommandContext - Error while closing command context
org.activiti.engine.ActivitiIllegalArgumentException: Variable contacts is not found
   at org.activiti.engine.impl.bpmn.behavior.MultiInstanceActivityBehavior.resolveNrOfInstances(MultiInstanceActivityBehavior.java:143)
   at org.activiti.engine.impl.bpmn.behavior.MultiInstanceActivityBehavior.execute(MultiInstanceActivityBehavior.java:97)
   at org.activiti.engine.impl.bpmn.behavior.SequentialMultiInstanceBehavior.execute(SequentialMultiInstanceBehavior.java:90)
   at org.activiti.engine.impl.pvm.runtime.AtomicOperationActivityExecute.execute(AtomicOperationActivityExecute.java:60)
   at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:97)
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:644)
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:637)
   at org.activiti.engine.impl.pvm.runtime.AtomicOperationTransitionNotifyListenerStart.eventNotificationsCompleted(AtomicOperationTransitionNotifyListenerStart.java:52)
   at org.activiti.engine.impl.pvm.runtime.AbstractEventAtomicOperation.execute(AbstractEventAtomicOperation.java:56)

I have gone through the activiti code too,

Below is the snippet of code from the class MultiInstaceActivityBehavior.java
public void execute(ActivityExecution execution) throws Exception {
    if (getLocalLoopVariable(execution, getCollectionElementIndexVariable()) == null) {
      try {
        createInstances(execution);
      } catch (BpmnError error) {
        ErrorPropagation.propagateError(error, execution);
      }

      if (resolveNrOfInstances(execution) == 0) {
        leave(execution);
      }
    } else {
        innerActivityBehavior.execute(execution);
    }
  }


while executing the multi instances it is creating successfully the number of instances to be created,
after finishing all the multi tasks
       if (resolveNrOfInstances(execution) == 0) {
        leave(execution);
      }
In the above code snippet it is checking again for the variables i have set earlier,
but those variables are already cleared while leaving the tasks execution.

Can you guide me where I am missing.

Thanks in advance.

Outcomes