Hello.
I modeled the following process:
TimerTest.bpmn (9.5 KB)
I want to to correlate ‘MSG_C’ in the sub process to spefic sub pocess instance identified by a variable.
If i remove ‘MSG_C’ from the sub process, i can see that the sub process has the variable ‘numberLocal’ set’ (which comes from the looped element variable ‘number’) by debugging the delegate of service task 'T3:
String number = (String) execution.getVariable("numberLocal");
→ gives me value ‘N1’.
I wonder if (including ‘MSG_C’ in the process model) i cant correlate the message to one of the sub processes by:
processEngine.getRuntimeService().createMessageCorrelation("MSG_C").processInstanceVariableEquals("numberLocal", "N1").correlate();
Error:
Cannot correlate a message with name 'MSG_C' to a single execution. {number of elements in ${numbers} collection} executions match the correlation keys
Of source, ‘N1’ is an element of the ${numbers} collection, which is the collection of the looped sub process.
I know that each sub process has its variable ‘numberLocal’ (see above).
Can you tell me what i am doing wrong?
Test case:
@Test
public void testTimer()
{
String bkMain = "bkMain1";
List<String> numbers = new ArrayList<>();
numbers.add("N1");
numbers.add("N2");
numbers.add("N3");
RuntimeService runtimeService = processEngine.getRuntimeService();
ProcessInstance instance = runtimeService.startProcessInstanceByKey("TimerTestProcess", bkMain,
MapBuilder.getInstance().addEntry("numbers", numbers).create());
runtimeService.correlateMessage("MSG_B", bkMain);
assertThat(instance).hasPassed("EV_MSG_B");
List<Task> taskT2List = processEngine.getTaskService().createTaskQuery().taskDefinitionKey("TASK_T2").list();
assertEquals(3, taskT2List.size());
// finsh all 'T2' tasks
for (Task t : taskT2List)
{
processEngine.getTaskService().complete(t.getId());
}
// works
// processEngine.getRuntimeService().createMessageCorrelation("MSG_C").correlateAll();
// what to for e.g. sub process with variable (${numberLocal == "N1"})? --> does NOT work
processEngine.getRuntimeService().createMessageCorrelation("MSG_C").localVariableEquals("numberLocal", "N1").correlate();
assertThat(instance).isEnded();
}