How to get the list of all variables from history?

I’m using HistoryVariableInstanceQuery to fetch all the list of TypedValue variables of a completed process.

HistoricVariableInstanceQuery historyVariableInstanceQuery = historyVariableInstanceQuery
				.createHistoricVariableInstanceQuery().processInstanceId("some id");

TypedValue characteristicValue = historyVariableInstanceQuery
				.variableName("some variable name").singleResult().getTypedValue();

But I have to each time call historyvariableInstanceQuery method to get individual TypedValue.
Is there any way that I can fetch all the variables of a completed process in a single query so that I dont have to query db each time I want to to get variables.

Hey @sunnyorange,

the HistoricVariableInstanceQuery also offers a list() method that queries the DB once and returns a list of HistoryVariableInstance objects. You could then process this list of variables in memory.

Hope that helps you!



HistoryVariableInstance return list of variables but only the ones from task local scope. Not the the variables accessible to task but at process instance level. Does anyone know how to get all variables accessible to task?

Hi @Suhas_Kulkarni,

This depends on how you use the query API. If you use the #taskIdIn method, you will only get the variables you describe. If you instead only use #processInstanceId you will get all historic variables related to that process instance, meaning all variables from local scopes and the process instance scope.

What you can do here is

  1. query for all historic variables of the process instance and
  2. iterate through that list and keep those that either have no taskId or one that equals the one of your task.

With that you should be able to find the variables you’re looking for.