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.
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.
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?
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
query for all historic variables of the process instance and
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.