TaskQuery .or() / .endOr() with loop dynamically

Hello,
While using TaskQuery i use .processVariableValueEquals() for getting the task i want,
However i also use the or() / endOr() for chaining some .processVariableValueEquals().
But this is not suffisant and i need to go deeper than this, i need to do it but dynamically (maybe i need 3 or 4 or even 5 .processVariableValueEquals() in some cases). After my research i’ve found this topic (TaskQuery for tasks of several processes) but all the reply don’t work at all, any way i’ve try with for loop is a failure.

As far as i am in my code (working) is :
taskQuery.or()
.processVariableValueEquals(CamundaVariable.REQUEST_TYPE, “ATTRIBUTE_CREATE”)
.processVariableValueEquals(CamundaVariable.REQUEST_TYPE, “VALUE_CREATE_STANDALONE”)
.endOr();

My attempt with a foor loop :

for (String strType : requestFilter.requestTypeList) {
taskQuery = taskQuery.or().processVariableValueEquals(CamundaVariable.REQUEST_TYPE, strType).endOr();
}

And with this way fail i don’t get anything.
Also it’s not possible to use something like this cause writing semicolon right after the or() throw an ecxeption :

taskQuery.or();
for (String strType : requestFilter.requestTypeList) {
taskQuery = taskQuery.processVariableValueEquals(CamundaVariable.REQUEST_TYPE, strType);
}
taskQuery.endOr();

So my question is : How can i use forloop inside the or() / endOr() ? If not is there a other way to achieve this ?

Thanks

I tried this

        TaskQuery query = this.taskService.createTaskQuery().or();
        for ( String s : Arrays.asList( "50/2019", "51/2019", "01/2020" ) ) {
            query = query.processVariableValueEquals( "Liefertermin", s );
        }
        List<Task> tasks = query.endOr().list();
        for ( Task task : tasks ) {
            ...
        }

to check, and it works fine. No exception.

@langfr in the first loop, after each iteration value to the query will be overridden to the current iteration.

@aravindhrs No, according to my test not.

In this test system I have 3 tasks with 2 different variable values for variable “Liefertermin”.
All are found, those with “Liefetermin” = “50/2019” as well as the one with “Lieftermin” = “51/2019”.
So the or-construct works for me as shown.

Thanks for the reply !
I post the working solution if someone have the same question in future

taskQuery = taskQuery.or();
for (String criteria : criteriaList) {
taskQuery.processVariableValueEquals(camundaVariable, criteria);
}
taskQuery = taskQuery.endOr();
taskList = taskQuery.listPage(firstResult, size);

1 Like