How to use the HistoryService API to get all variables (changed or not) of a process?

1,462 views
Skip to first unread message

Melissa Palmer

unread,
Mar 5, 2015, 5:18:56 AM3/5/15
to camunda-...@googlegroups.com
Hi 

Using the API how can you get all HistoricDetail for a process even if the variable has not been changed? 

Currently I am using 
   List<HistoricDetail> historicDetailInstance = BpmPlatform.getDefaultProcessEngine().getHistoryService().createHistoricDetailQuery().processInstanceId(processInstanceId).list();

I see you there is a variableUpdates() function that might help such as: 
   List<HistoricDetail> historicDetailInstance = BpmPlatform.getDefaultProcessEngine().getHistoryService().createHistoricDetailQuery().processInstanceId(processInstanceId).variableUpdates().list();

Problem is that the above two lines of code seem to return the same set of data? 

Using the API I want to get to the same point that the REST API for http://docs.camunda.org/latest/api-references/rest/#history-get-historic-details which returns all variables changed or not. 

Thanks
Melissa

thorben....@camunda.com

unread,
Mar 6, 2015, 4:33:44 AM3/6/15
to camunda-...@googlegroups.com
Hi Melissa,

Initial variable values are also treated as variable updates. That means, the query

BpmPlatform.
getDefaultProcessEngine().getHistoryService().createHistoricDetailQuery().processInstanceId(processInstanceId).variableUpdates().list()

returns the initial variable values as well as any update. By the way: the REST API makes exactly that query when you set the processInstanceId and variableUpdates parameters accordingly.

In general, the historic details table stores two things: variable updates and submitted form properties. With the filter #variableUpdates(), you can exclude the form properties.

Cheers,
Thorben

Melissa Palmer

unread,
Mar 6, 2015, 6:56:56 AM3/6/15
to camunda-...@googlegroups.com
Hi Thorben, 

Ok thanks for that explanation... however I am still not quite sure how to solve my issue. Maybe I am looking in the wrong place. 

How can I get all variables whether they were updated or not? 
We need to show the full process variable history to a user on a task node (and especially those processes where users where asked to Amend something). 

For example: For the process below. All UserTask nodes need to display a Full Process history in the UI to a user. 
If the process below followed the "Amend" route and when user amended the details they only change 2 of 10 variables. 
On the history page we want to show all 10 variables as they were at that point (changed or not) 
                          ------------------------------------------|
                         
|                                         |
                         
|                                         |
                         
|                       |----  Amend -----|
 
Start -> UserTaskEnterData -> ApprovalUserTask --|
                                                 
|----  Approve






Thanks
Melissa

thorben....@camunda.com

unread,
Mar 6, 2015, 7:16:06 AM3/6/15
to camunda-...@googlegroups.com
Hi Melissa,

Thanks for providing the example.

It is currently not possible to express such a "time travel" query via API. The historic detail query always gives you all updates, regardless of the time they occurred. Of course you could filter these updates in your application but this means unnecessary data transfer overhead.

I would have advised you to implement a native query [1] but found that there is currently no API method to create a native query for historic details. I created a feature request for that, see [2].

Cheers,
Thorben

[1] http://docs.camunda.org/latest/guides/user-guide/#process-engine-process-engine-api-native-queries
[2] https://app.camunda.com/jira/browse/CAM-3597

Melissa Palmer

unread,
Mar 6, 2015, 7:23:12 AM3/6/15
to camunda-...@googlegroups.com
Hi Thorben

Ok thanks for that.

Do I understand correctly that "History Service" only returns updates? 
If a variable was not changed it will not be "saved" into the history tables? 

Thanks
Melissa

thorben....@camunda.com

unread,
Mar 6, 2015, 7:27:40 AM3/6/15
to camunda-...@googlegroups.com
Hi Melissa,

No, unchanged variables will be returned by a HistoricDetailQuery. That is what I was trying to say before that the creation of a variable is treated like an update and therefore returned among the other updates.

Unchanged variables are also accessible via the HistoricVariableInstanceQuery that always returns the latest value of a variable.

Best regards,
Thorben
Reply all
Reply to author
Forward
0 new messages