cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with multi instance workflow

babjikundateeri
Champ in-the-making
Champ in-the-making
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.
2 REPLIES 2

trademak
Star Contributor
Star Contributor
Hi,

Can you check in the database if the contacts variable is created in the ACT_RU_VARIABLE table?
If you can share a unit test project showing the error, so we can easily reproduce it that would be helpful.
I don't see any immediate issues with your code.

Best regards,

Hi Tijs,

Thank you for the replay.
I have checked data base, there is a entry created in  ACT_RU_VARIABLE table with name contacts.

In my case, Multi Instance will create 2 instances (As Collection is of size 2)

I have enabled debug logs of activiti,
please find below lines of logs from activiti, It might help you to understand my problem.

2016-08-29 12:23:47 [SimpleAsyncTaskExecutor-6] DEBUG o.a.e.i.b.b.MultiInstanceActivityBehavior - Multi-instance 'Activity(sid-529216C6-05D3-48E2-BB15-4B52B351B60D)' instance completed. Details: loopCounter=1, nrOrCompletedInstances=2,nrOfActiveInstances=0,nrOfInstances=2
2016-08-29 12:23:47 [SimpleAsyncTaskExecutor-6] DEBUG o.a.e.i.p.entity.ExecutionEntity - inactive concurrent executions in 'Activity(sid-529216C6-05D3-48E2-BB15-4B52B351B60D)': [ConcurrentExecution[22565], ConcurrentExecution[22566]]
2016-08-29 12:23:47 [SimpleAsyncTaskExecutor-6] DEBUG o.a.e.i.p.entity.ExecutionEntity - other concurrent executions: []
2016-08-29 12:23:47 [SimpleAsyncTaskExecutor-6] DEBUG o.a.e.i.p.entity.ExecutionEntity - transitions to take concurrent: [(sid-529216C6-05D3-48E2-BB15-4B52B351B60D)–sid-C75A9F40-14BD-4BB5-81CD-3A9437506123–>(sid-9AA4E29B-C9F3-451D-86D6-62F030ECCC40)]
2016-08-29 12:23:47 [SimpleAsyncTaskExecutor-6] DEBUG o.a.e.i.p.entity.ExecutionEntity - active concurrent executions: []


2016-08-29 12:23:47 [SimpleAsyncTaskExecutor-6] DEBUG o.a.e.i.b.b.MultiInstanceActivityBehavior - Multi-instance 'Activity(sid-529216C6-05D3-48E2-BB15-4B52B351B60D)' instance completed. Details: loopCounter=0, nrOrCompletedInstances=1,nrOfActiveInstances=1,nrOfInstances=2
2016-08-29 12:23:47 [SimpleAsyncTaskExecutor-6] DEBUG o.a.e.i.p.entity.ExecutionEntity - inactive concurrent executions in 'Activity(sid-529216C6-05D3-48E2-BB15-4B52B351B60D)': [ConcurrentExecution[22565]]
2016-08-29 12:23:47 [SimpleAsyncTaskExecutor-6] DEBUG o.a.e.i.p.entity.ExecutionEntity - other concurrent executions: []
2016-08-29 12:23:47 [SimpleAsyncTaskExecutor-6] DEBUG o.a.e.i.p.e.V.selectVariablesByExecutionId - ==>  Preparing: select * from ACT_RU_VARIABLE where EXECUTION_ID_ = ? and TASK_ID_ is null
2016-08-29 12:23:47 [SimpleAsyncTaskExecutor-6] DEBUG o.a.e.i.p.e.V.selectVariablesByExecutionId - ==> Parameters: 22566(String)
2016-08-29 12:23:47 [SimpleAsyncTaskExecutor-6] DEBUG o.a.e.i.p.e.V.selectVariablesByExecutionId - <==      Total: 0


2016-08-29 12:23:47 [SimpleAsyncTaskExecutor-6] DEBUG o.a.e.i.p.entity.ExecutionEntity - activating the concurrent root ScopeExecution[22560] as the single path of execution going forward
2016-08-29 12:23:47 [SimpleAsyncTaskExecutor-6] DEBUG o.a.e.i.h.DefaultHistoryManager - Current history level: AUDIT, level required: ACTIVITY
2016-08-29 12:23:47 [SimpleAsyncTaskExecutor-6] DEBUG o.a.e.i.p.r.AtomicOperationTransitionDestroyScope - destroy scope: scoped ScopeExecution[22560] continues as parent scope ProcessInstance[22552]
2016-08-29 12:23:47 [SimpleAsyncTaskExecutor-6] DEBUG o.a.e.i.p.entity.ExecutionEntity - destroying ScopeExecution[22560]

2016-08-29 12:23:47 [SimpleAsyncTaskExecutor-6] DEBUG o.a.e.i.p.r.AtomicOperationTransitionDestroyScope - destroy scope: scoped ScopeExecution[22560] continues as parent scope ProcessInstance[22552]
2016-08-29 12:23:47 [SimpleAsyncTaskExecutor-6] DEBUG o.a.e.i.p.entity.ExecutionEntity - destroying ScopeExecution[22560]
2016-08-29 12:23:47 [SimpleAsyncTaskExecutor-6] DEBUG o.a.e.i.h.DefaultHistoryManager - Current history level: AUDIT, level required: ACTIVITY
2016-08-29 12:23:47 [SimpleAsyncTaskExecutor-6] DEBUG o.a.e.i.h.DefaultHistoryManager - Current history level: AUDIT, level required: ACTIVITY
2016-08-29 12:23:47 [SimpleAsyncTaskExecutor-6] DEBUG o.a.e.i.h.DefaultHistoryManager - Current history level: AUDIT, level required: ACTIVITY
2016-08-29 12:23:47 [SimpleAsyncTaskExecutor-6] DEBUG o.a.e.i.h.DefaultHistoryManager - Current history level: AUDIT, level required: ACTIVITY
2016-08-29 12:23:47 [SimpleAsyncTaskExecutor-6] DEBUG o.a.engine.impl.db.DbSqlSession - skipping redundant delete: VariableInstanceEntity[id=22564, name=nrOfActiveInstances, type=integer, longValue=0, textValue=0]
2016-08-29 12:23:47 [SimpleAsyncTaskExecutor-6] DEBUG o.a.e.i.h.DefaultHistoryManager - Current history level: AUDIT, level required: ACTIVITY
2016-08-29 12:23:47 [SimpleAsyncTaskExecutor-6] DEBUG o.a.engine.impl.db.DbSqlSession - skipping redundant delete: VariableInstanceEntity[id=22562, name=nrOfInstances, type=integer, longValue=2, textValue=2]
2016-08-29 12:23:47 [SimpleAsyncTaskExecutor-6] DEBUG o.a.e.i.h.DefaultHistoryManager - Current history level: AUDIT, level required: ACTIVITY
2016-08-29 12:23:47 [SimpleAsyncTaskExecutor-6] DEBUG o.a.engine.impl.db.DbSqlSession - skipping redundant delete: VariableInstanceEntity[id=22563, name=nrOfCompletedInstances, type=integer, longValue=2, textValue=2]

2016-08-29 12:23:47 [SimpleAsyncTaskExecutor-6] DEBUG o.a.e.i.p.r.AtomicOperationTransitionNotifyListenerTake - ProcessInstance[22552] takes transition (sid-529216C6-05D3-48E2-BB15-4B52B351B60D)–sid-C75A9F40-14BD-4BB5-81CD-3A9437506123–>(sid-9AA4E29B-C9F3-451D-86D6-62F030ECCC40)


2016-08-29 12:23:47 [SimpleAsyncTaskExecutor-6] DEBUG o.a.e.i.h.DefaultHistoryManager - Current history level: AUDIT, level required: ACTIVITY
2016-08-29 12:23:47 [SimpleAsyncTaskExecutor-6] DEBUG o.a.engine.impl.db.DbSqlSession - skipping redundant delete: VariableInstanceEntity[id=22557, name=contacts, type=jpa-entity-list, textValue=com.fealti.data.accounts.Contact]
2016-08-29 12:23:47 [SimpleAsyncTaskExecutor-6] DEBUG o.a.e.i.p.e.T.selectTasksByExecutionId - ==>  Preparing: select distinct T.* from ACT_RU_TASK T where T.EXECUTION_ID_ = ?
2016-08-29 12:23:47 [SimpleAsyncTaskExecutor-6] DEBUG o.a.e.i.p.e.T.selectTasksByExecutionId - ==> Parameters: 22552(String)
2016-08-29 12:23:47 [SimpleAsyncTaskExecutor-6] DEBUG o.a.e.i.p.e.T.selectTasksByExecutionId - <==      Total: 0
2016-08-29 12:23:47 [SimpleAsyncTaskExecutor-6] DEBUG o.a.e.i.p.e.J.selectJobsByExecutionId - ==>  Preparing: select * from ACT_RU_JOB J where J.EXECUTION_ID_ = ?
2016-08-29 12:23:47 [SimpleAsyncTaskExecutor-6] DEBUG o.a.e.i.p.e.J.selectJobsByExecutionId - ==> Parameters: 22552(String)
2016-08-29 12:23:47 [SimpleAsyncTaskExecutor-6] DEBUG o.a.e.i.p.e.J.selectJobsByExecutionId - <==      Total: 1
2016-08-29 12:23:47 [SimpleAsyncTaskExecutor-6] DEBUG o.a.e.i.p.e.I.selectIdentityLinksByProcessInstance - ==>  Preparing: select * from ACT_RU_IDENTITYLINK where PROC_INST_ID_ = ?
2016-08-29 12:23:47 [SimpleAsyncTaskExecutor-6] DEBUG o.a.e.i.p.e.I.selectIdentityLinksByProcessInstance - ==> Parameters: 22552(String)
2016-08-29 12:23:47 [SimpleAsyncTaskExecutor-6] DEBUG o.a.e.i.p.e.I.selectIdentityLinksByProcessInstance - <==      Total: 0
2016-08-29 12:23:47 [SimpleAsyncTaskExecutor-6] 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.pvm.runtime.AtomicOperationActivityExecute.execute(AtomicOperationActivityExecute.java:60)
at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:97)