Camunda: query processes that do not have a specific variable

Viewed 1011

In Camunda (7.12) I can query processes by variable value:

runtimeService.createProcessInstanceQuery()
  .variableValueEquals("someVar", "someValue")
  .list();

I can even query processes for null-value variables:

runtimeService.createProcessInstanceQuery()
  .variableValueEquals("someVar", null)
  .list();

But how can I query processes that do not have variable someVar?

2 Answers

I am not sure why you wouldn't have figured that out, but if i am correct what i think you are looking for , then looks like its pretty simple . The ProcessInstanceQuery class has also a method called variableValueNotEquals(String name, Object value) , that allows you select the processes that do not match a variable . In the Camunda Java API Docs it is stated as :

variableValueNotEquals(String name, Object value)
Only select process instances which have a global variable with the given name, but with a different value than the passed value.

Documentation page for your reference:

https://docs.camunda.org/javadoc/camunda-bpm-platform/7.12/?org/camunda/bpm/engine/RuntimeService.html

So i believe you can simply do :

runtimeService.createProcessInstanceQuery()
  .variableValueNotEquals("someVar", null)
  .list();

Let me know if that helps you .

First, get list of ids of all process instances which have "someVar"

Second, get list of all process ids in camunda

Get ids, from second list, which are not contained in first list.

Here is Kotlin sample as it's shorter than Java code, but concept is the same:

    val idsOfProcessesWithVar = runtimeService.createVariableInstanceQuery().variableName("someVar").list().map {
        it.processInstanceId
    }

    val allProcessesIds = runtimeService.createProcessInstanceQuery().list().map { it.id }

    allProcessesIds.minus(idsOfProcessesWithVar)
Related