cancel
Showing results for 
Search instead for 
Did you mean: 

History and multi instance SubProcess

iam
Champ in-the-making
Champ in-the-making
Hi, guys.
I'm playing with retrieving historical sequence way for process instance and was confused a little bit by the case with multi instance sub process (not a call activity).
I have SubProcess with loop cardinality 3 and there are some activities in the sub process.
When I get historical activity instances like that:

    List<HistoricActivityInstance> historicActivityInstances = historyService.createHistoricActivityInstanceQuery()
        .processInstanceId(processInstanceId).orderByHistoricActivityInstanceStartTime().asc().list();

I can not determine which subprocess loop instance contains which activities.

Real example: I have three phones and multi instance sub process for this three phones. Each instance will make call and analyze call result code to send SMS when no answer. After that I want to know (and see) each way for each sub process instance.
Is it possible?
Yes, I know I can use call activity, but my actualy goal is retrieve correct sequence way for any type of designed processes.

And one strange thing more: executionId of the first sub process instance looks strange - i.e. "9" when other instances have "20" and "22". I expected something like 18, I've analized tables and dont understand why ACT_HI_ACTINST has executionId "9" as scope just for the first instance.
I tried to retrieve historical variables:

historyService.createHistoricVariableInstanceQuery().executionId("9").list()

Historic variables for executionId=9 realy looks like scope variables with "nrOfInstances" and other two (20 and 22) have "loopCounter".
The question is: where is my loopCounter for the first instance? Smiley Happy
3 REPLIES 3

jbarrez
Star Contributor
Star Contributor
Not sure if I'm following, but: multi instance won't show up in the history logs, only multiple historic activities. Which I agree, is not really nice and we should make that better.

iam
Champ in-the-making
Champ in-the-making
Thanks, Joram.
I've done simplest test with multi instance script task and the history log looks… a little bit unexpected:

ACT_HI_ACTINST
[table][tr][h]ID_[/h][h]PROC_DEF_ID_[/h][h]PROC_INST_ID_[/h][h]EXECUTION_ID_[/h][h]ACT_ID_[/h][/tr]
[tr][td]6[/td][td]testProcessA:1:4[/td][td]5[/td][td]5[/td][td]startevent1[/td][/tr]
[tr][td]10[/td][td]testProcessA:1:4[/td][td]5[/td][td]9[/td][td]scripttask1[/td][/tr]
[tr][td]26[/td][td]testProcessA:1:4[/td][td]5[/td][td]18[/td][td]scripttask1[/td][/tr]
[tr][td]31[/td][td]testProcessA:1:4[/td][td]5[/td][td]19[/td][td]scripttask1[/td][/tr]
[tr][td]34[/td][td]testProcessA:1:4[/td][td]5[/td][td]5[/td][td]endevent3[/td][/tr]
[/table]

ACT_HI_VARINST
[table][tr][h]ID_[/h][h]PROC_INST_ID_[/h][h]EXECUTION_ID_[/h][h]NAME_[/h][/tr]
[tr][td]7[/td][td]5[/td][td]5[/td][td]orderId[/td][/tr]
[tr][td]11[/td][td]5[/td][td]9[/td][td]nrOfInstances[/td][/tr]
[tr][td]13[/td][td]5[/td][td]9[/td][td]nrOfCompletedInstances[/td][/tr]
[tr][td]15[/td][td]5[/td][td]9[/td][td]nrOfActiveInstances[/td][/tr]
[tr][td]20[/td][td]5[/td][td]17[/td][td]loopCounter[/td][/tr]
[tr][td]24[/td][td]5[/td][td]18[/td][td]loopCounter[/td][/tr]
[tr][td]29[/td][td]5[/td][td]19[/td][td]loopCounter[/td][/tr]
[/table]

Execution "9" is a scope. If we would not have this executionId in ACT_HI_ACTINST then we will not know how to retrieve "nrOfCompletedInstances" by executionId.
On the other hand.. if we dont have execution "17" in ACT_HI_ACTINST then we dont know nothing about execution with loopCounter=0

/

And about executions:

In runtime I've got each of the three execution using breakpoint in some test method of my test bean.
I always use Context.getExecutionContext().getExecution() in my beans to use current execution, I actualy do not use execution as argument in processes.
It was surprise: the first execution was a ScopeExecution, the second and the third was ConcurrentExecutions.
I just try to modify MultiInstanceActivityBehavior from
[java]
    if (loopCounter == 0) {
        callCustomActivityStartListeners(execution);
        innerActivityBehavior.execute(execution);
    } else {
      execution.executeActivity(activity);
    }
[/java]
to
[java]
    if (loopCounter == 0) {
      callCustomActivityStartListeners(execution);
      try {
        Context.setExecutionContext((ExecutionEntity)execution);
        innerActivityBehavior.execute(execution);
      } finally {
        Context.removeExecutionContext();
      }
    } else {
      execution.executeActivity(activity);
    }
[/java]
I'm not shure if that was correct to set Execution Context there, but after that Context.getExecutionContext().getExecution() returns ConcurrentExecutions for each parallel instances.

jbarrez
Star Contributor
Star Contributor
One thing to note ios that the execution id in the ACT_HI_ACTINST is not really usable to correlate with the ACT_HI_VARINST, as it's not necessarily the execution that enters the activity that will be used to set variables.

I'm not following you remark about setting the ExecutionContext. To my knowledge, that class serves a few use cases (getting the context in case of job failure is one I believe). If you'd want to rely on that call, it would need to be added on many more behaviours besides the MultiInstance behaviour.