REST API - Query Process Instance without variable

Hi there, I’m trying to search for instances that does not contain a certain boolean variable, this variable is always set to true when it exists. I tried doing this:

/history/process-instance?variables=myVar_neq_true

but that query does not work, just like this user found out REST-API: filtering process instances by variables and operator does not work properly

So my question is how can I correctly query these instances using the REST API?

Hello Mr. Jordan!
Welcome to community!

Trying to use it:

POST
https://localhost:8080/engine-rest/history/process-instance

{
  "variables": [
    {
        "name": "fluxoRiscoFinalizado",
        "operator": "neq",
        "value": false
    }
  ],
  "sorting":[
    {
      "sortBy": "businessKey",
      "sortOrder": "asc"
    },
    {
      "sortBy": "startTime",
      "sortOrder": "desc"
    }
  ]
}

Below you can see the results:

If this answer solved your doubt, please mark it as “Solution”, so that future members who have the same doubt can find the answer quickly.

I hope this helps.

William Robert Alves

1 Like

Hi William!
I actually wanna query the opposite: all instances that don’t have “fluxoRiscoFinalizado” set to True, including not having that variable. I couldn’t find a “variable not exists” as an option for the query, which would make sense here. Do you see an alternative maybe?
Obrigado!

Hi \o

Please try doing it as follows below and see if it works:
Since you are querying history, I suggest you add the query param firstResult and maxResult in your url.

POST
https://localhost:8080/engine-rest/history/process-instance?maxResults=5&firstResult=1

  "variables": [
    {
        "name": "myVar",
        "operator": "neq",
        "value": true
    },
    {
        "name": "myVar",
        "operator": "eq",
        "value": null
    }    
  ],
  "sorting":[
    {
      "sortBy": "businessKey",
      "sortOrder": "asc"
    },
    {
      "sortBy": "startTime",
      "sortOrder": "desc"
    }
  ]
}

I hope this helps.

William Robert Alves

I tried using both filters and the “eq null” by itself, it unfortunately doesn’t help… Seems like an engine limitation? I already found another indirect way to solve my real problem (instead of finding instances that didn’t set this variable, filter out instances that went through the task that sets the variable), but it would be great to have this feature somehow fixed

Hi @Jordi

orQueries should be used, and myVar must always be present, either holding a boolean value or set to null.

{
    "orQueries": [
        {
            "variables": [
                {
                    "name": "myVar",
                    "operator": "neq",
                    "value": true
                },
                {
                    "name": "myVar",
                    "operator": "eq",
                    "value": null
                }
            ]
        }
    ]
}
2 Likes

Hi @hassang
Unfortunately making myVar always present would be the “ugliest” choice for my use case. I managed to solve my issue with a task query instead of process instance query as mentioned earlier, which makes the variable obsolete.
Regardless it is important to be clear for other looking for this answer that you really cannot query process instances with a “variable NOT EXISTS” then.
Thanks everyone for the help!

2 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.