I have a workflow with a sub-process running in parallel.
or here an xml extract:
<process id="hello" name="Hello" isExecutable="true" flowable:candidateStarterGroups="flowableUser">
<subProcess id="subProcess" name="Parallel Sub Process">
<multiInstanceLoopCharacteristics isSequential="false" flowable:collection="insurers" flowable:elementVariable="insurerId">
</multiInstanceLoopCharacteristics>
The workflow is started with a process variable ‘insurers’ containing a set of ifs.
String start(Set<String> insurers) {
var process = runtimeService.startProcessInstanceByKey("hello", Map.of(INSURERS, insurers));
return process.getProcessInstanceId();
}
The sub-process is configured as follow:
I.e., every element of the collection instantiates a sub-process.
How can I query the user task by searching the element variable.
I tried the following:
- Querying the process variable
void completeTask(String processInstanceId, String insurerId){
List<Task> tasks = taskService.createTaskQuery()
.processInstanceId(processInstanceId)
.processVariableValueEquals(INSURER_ID, insurerId)
.list();
This does not work, both (assuming I started the workflow with 2 insurerIds) tasks are returned.
2. Querying with task variable
void completeTask(String processInstanceId, String insurerId){
List<Task> tasks = taskService.createTaskQuery()
.processInstanceId(processInstanceId)
.taskVariableValueEquals(INSURER_ID, insurerId)
.list();
This doesn’t return any task.
3. Querying by hand
That last one works, but is not really how I would like to solve the problem
void completeTask(String processInstanceId, String insurerId){
List<Task> tasks = taskService.createTaskQuery()
.processInstanceId(processInstanceId)
.processVariableValueEquals(INSURER_ID, insurerId)
.list()
.stream().filter(task -> {
Object variable = taskService.getVariable(task.getId(), INSURER_ID);
return Objects.equals(variable, insurerId);
})
.toList() ;
So how can I query an element variable