Query Task Variables with AND/OR

I’ve searched the topics but don’t see an answer for this Task Query or Filter question. We have a need to find User Tasks based on a combination of several Process Variables. In the absence of an in-list capability we would be looking for something like this:

(Variable1 = 'A' or Variable1 = 'B' or Variable1 = 'C')
AND
(Variable2 = 'AA or Variable2 = 'BB' or Variable2 = 'CC')

Is that at all possible via the REST API? If not, how have others overcome accomplished more complex queries?

Hey @Bill_Powell,

this is indeed not possible via the REST API. You may have seen that you can use orQueries, but you can not chain muiltiple of those in one REST call.
https://docs.camunda.org/manual/7.11/reference/rest/task/post-query/#request-with-or-queries

What you could do is make two calls with each using one orQueries object and compare the result set manually.

In the Java API you could achieve this as you can use multiple .or().endOr() blocks there.

taskService.createTaskQuery()
.or().taskVariableValueEquals("Variable1", "A").taskVariableValueEquals("Variable1", "B").endOr()
.or().taskVariableValueEquals("Variable2", "AA").taskVariableValueEquals("Variable2", "BB").endOr()
.list();

https://docs.camunda.org/javadoc/camunda-bpm-platform/7.11/org/camunda/bpm/engine/task/TaskQuery.html

I hope this helps you.
Cheers,
Miklas

Thanks, Miklas. If I am to cross the java boundary :wink: I am wondering what would be the simplest approach to do this. Currently, my applications use the Camunda engines via the REST API, with extensive use of External Tasks and a small amount of Groovy scripting in Listeners.

If I wanted to leverage the Java SDK/API for the rare case where the REST interface doesn’t provide the exact functionality I need, would a Java engine plug-in make sense? For the use case in this thread, I am wanting to basically extend the REST API to provide a query capability that doesn’t exist or would be inefficient with the existing endpoints. My team has limited java experience and would look for the simplest approach.

I see there are many existing posts on options for extending the REST api, etc. Plenty of food for thought.

Hi @Bill_Powell,

I think the easiest solution would be to embedd th REST API into a web application that could then extend/modify the existing API endpoints or even add new ones.

The REST API has its own artifact wich makes it possible to write an application that wraps around this and modifies it. A guide about how this is done can be found in the docs. https://docs.camunda.org/manual/latest/reference/rest/overview/embeddability/

Cheers,
Miklas

Hello

This orQuery should work to cover the example query in the question:
{
“orQueries”:[
{
“processVariables”: [{“name”: “Variable1”,
“operator”: “eq”,
“value”: “A”
},
{“name”: “Variable1”,
“operator”: “eq”,
“value”: “B”
},
{“name”: “Variable1”,
“operator”: “eq”,
“value”: “C”
}]
},
{
“processVariables”: [{“name”: “Variable2”,
“operator”: “eq”,
“value”: “AA”
},
{“name”: “Variable2”,
“operator”: “eq”,
“value”: “BB”
},
{“name”: “Variable2”,
“operator”: “eq”,
“value”: “CC”
}]
}
]
}

Kind regards,
Olga

3 Likes