Search in history all the processes that had a variable


I have a process that has two variables in the context, one is userId and the other one is comment, I want to find all the comments of the user using the history service.

I tried to get the process instances but they don’t have the variables, I was able to find the history values for the userId and for the comments but didn’t manage to find them in combination.

In case is not clear I want something similar to this query:
Select comments from historyService
where userId= input.

I didn’t manage to find something, do you have any suggestions?

You should be able to link the variable pairs by their procInstId in the history table…

I only managed to search only by one variable:


But I didn’t find a way to get the comments for this user

After you got your list of userIDs you should be able to get each processInstanceId of each userID-Variable ( getProcessInstanceId ())
Since there seems to be no processInstanceIdIn() you got to loop over those processInstanceIds and query for the comments variables associated with each of those Ids. ( processInstanceId(String processInstanceId).variableId(String id) )

Hope this helps.

1 Like


I managed to do it like this:

  final List<HistoricVariableInstance> historicVariableInstances = engine.getHistoryService().createHistoricVariableInstanceQuery()
                .variableValueEquals("userdId", "421")

Then get the processInstanceId for that user.

 List<String> processInstanceIds =;

And after that get the historic variable for the comment

List historicVariableInstances = engine.getHistoryService().createHistoricVariableInstanceQuery().processInstanceIdIn(processInstanceIds .stream().toArray(String[]::new)).variableName(“comment”).list();

I didn’t manage to find a easier way but this works for the moment.