Set process variable to null value, but can not query processes with null value

I found that we can set variable value to null by calling the API RuntimeService.setVariable, but we can not query processes which has null value for specific variable name.

my opinion is, this is not very reasonable, we should not allow variable set to null, or else, we should allow user to query by null value.

Java doc of ProcessInstanceQuery:

  /**
   * Only select process instances which have a global variable with the given value. The type
   * of variable is determined based on the value, using types configured in
   * {@link ProcessEngineConfiguration#getVariableSerializers()}.
   * Byte-arrays and {@link Serializable} objects (which are not primitive type wrappers)
   * are not supported.
   * @param name name of the variable, cannot be null.
   */
  ProcessInstanceQuery variableValueEquals(String name, Object value);

Java doc of RuntimeService

  /**
   * Update or create a variable for an execution.  If the variable does not already exist
   * somewhere in the execution hierarchy (i.e. the specified execution or any ancestor),
   * it will be created in the process instance (which is the root execution).
   *
   * @param executionId id of process instance or execution to set variable in, cannot be null.
   * @param variableName name of variable to set, cannot be null.
   * @param value value to set. When null is passed, the variable is not removed,
   * only it's value will be set to null.
   *
   * @throws ProcessEngineException
   *          when no execution is found for the given executionId.
   * @throws AuthorizationException
   *          if the user has no {@link Permissions#UPDATE} permission on {@link Resources#PROCESS_INSTANCE}
   *          or no {@link Permissions#UPDATE_INSTANCE} permission on {@link Resources#PROCESS_DEFINITION}.
   */
  void setVariable(String executionId, String variableName, Object value);

Equals and NotEquals queries should work properly with Null values…

1 Like

@hassang It works, thanks for your answer