Retrieve only defined set of variables in historic process instances

With historyService.createHistoricProcessInstanceQuery() we can retrieve either no variables along with process instances or all variables for all process instances.
However I need to retrieve only limited set of variables(to show them in UI for each process instance - kind of summary) to avoid performance issues(process instances may have huge sets of variables with huge values).
Can you suggest some existing solution? Or custom query is the only solution for my problem?

Hi @simonovdenis,

how about the HistoricVariableInstanceQuery you can create via historyService.createHistoricVariableInstanceQuery()?

You can specify the process instance and even specific variable names you want to fetch variables for. And you can limit the number of variables you want to fetch as well by invoking listPage() on the created query. Does that fit your needs?

Best,
Tobias

@tmetzke what is the equivalent rest api for this java api? And same can be achieved for runtime task/process variable instances?

Hi @aravindhrs,

the REST API equivalent can be found here:
https://docs.camunda.org/manual/latest/reference/rest/history/variable-instance/post-variable-instance-query/

In the runtime, you can use runtimeService.createVariableInstanceQuery().
The REST API equivalent can be found here:
https://docs.camunda.org/manual/latest/reference/rest/variable-instance/post-query/

Best,
Tobias

i hope this api won’t allow to query for array of variableNames. I would like to query like this,

{
 "processDefinitionKey":"processDefinitionKey",
 "processInstanceId":"processInstanceId",
 "variableName": ["someVariableA","someVariableB","someVariableC"]
}

So idea is, for given process instances, i would like to retrieve variables only for the specified variable names in the json request body.

And the expected response is filtered by variable names:

[
  {
    "id": "someId",
    "name": "someVariableA",
    "type": "Integer",
    "variableType": "integer",
    "value": 5,
	.....
  },{
    "id": "someId",
    "name": "someVariableB",
    "type": "Integer",
    "variableType": "integer",
    "value": 5,
	.....
  }{
    "id": "someId",
    "name": "someVariableC",
    "type": "Integer",
    "variableType": "integer",
    "value": 5,
	.....
  }
]

Hi @aravindhrs,

at the moment, only the Java API for the runtime variables query allows to enter multiple variable names with variableNameIn.
The corresponding REST API as well as the historic variable queries do not support this.

Feel free to open a feature request in the Issue Tracker or to open a Pull Request in the repository that adds this feature.

Best,
Tobias

@tmetzke, thanks, will do it.

Actually, that is not exactly, what I was asking about. If I need to retrieve process instances and some of their variables I need to make 1 + N*V queries.
First to find the list of process instances:

historyService.createHistoricProcessInstanceQuery()…list()

and then iterate one by one(N process instances) to retrieve defined set of their variable instances(V):

variablesToRetrieve.forEach(v -> getProcessVariables(historyService, pi, v))

where

private List getProcessVariables(HistoryServiceImpl historyService, org.flowable.engine.history.HistoricProcessInstance pi, String variableName) {
return historyService.createHistoricVariableInstanceQuery()
.processInstanceId(pi.getId())
.variableName(variableName)
.list().stream().map(hvi -> (HistoricVariableInstanceEntity) hvi).collect(Collectors.toList());
}

What I want is to retrieve everything in 1 call via

HistoricProcessInstanceQuery…variableNameIn(…).list()

or at least all variables for one process instance in 1 call(totally 1+ N) via

HistoricVariableInstanceQuery.processInstanceId(processInstanceId).variableNameIn(…).list()

.

Hi @simonovdenis,

as I stated, this is currently not possible via Java API for historic data, only for runtime data.

Best,
Tobias