Filtertering tasks using values from JSON string

Hi everyone!

I have a process that starts with REST API and some values are passed in JSON format.
{
“variables”: {
“formData”: {
“value”: “{“customer”:{“id”:{“value”:“12345”}},“some_other_fields”:“value”}”,
“type”: “Object”,
“valueInfo”: {
“serializationDataFormat”:“application/json”,
“objectTypeName”:“com.package.class”
}
}
}
}
I need to filter tasks in Tasklist using the value from formData.customer.id.value. My understanding is that I have to create a filter that will give me all the tasks for a given process and then use “Search for tasks” functionality to additionally reduce task list. I see that it is possible to search for Process variables, Task variables and Case variables, but I just can’t get the variable type, name and value right. Is it possible to achieve?

With best regards
Dmitry

Hi Dmitry Sdk,

Only primitive types can be used in filtering.
See below link
https://docs.camunda.org/manual/7.5/user-guide/process-engine/variables/#supported-variable-values
(Primitive values differ from other variable values in that they can be used in API queries such as process instance queries as filtering conditions.)

The easiest way is to create a process variable of type string to store customer id & keep its value in sync with the corresponding value in the custom object “formData”
That primitive type variable can be used in filtering conditions

3 Likes

Thank you very much for quick answer! I will try that out :slight_smile:

In the past I tried to create a filter which filters based on a process variable value but it cannot be done it seems (tried that in version 7.4 and 7.5).
In the criteria I can only select values like business key, process/task/… name, process/task/… descriptions, etc.

JSON filtering support sounds like it would be a good feature request.

3 Likes

@camunda any ideas on level of effort to implement this?

Looking at adding this ability to cockpit to filter process instances based on json values.

1 Like

Hi Stephen,

I consider the effort rather high if it is possible to build this at all.

  1. To build this properly, the filtering must be implemented in the SQL query that fetches the variables from the database or else it will perform badly and things like query pagination become very complex.
  2. There are many ways to write a JSON object such that it is semantically the same object, e.g. you can insert an infinite amount of white space or, more realistically, you can change the order of properties. So a byte-by-byte comparison of values would probably not be sufficient to build a useful feature.
  3. 1 and 2 lead to the conclusion that the database management system must be able to semantically compare JSON values. I don’t believe all of Camunda’s supported databases have this capability.

Cheers,
Thorben

2 Likes

Thanks for the in-depth thinking!

So based on that thinking, would imagine that we need SQL JSON Query support across all supported DBs.

Hello @StephenOTT

I have a question regarding this.
Wanted to know if this feature is added to Camunda in 2022 or not. To filter by the json object.
For example get all the processInstances where it has a json variable which one the properties of that json variable has the value we are searching for.