cancel
Showing results for 
Search instead for 
Did you mean: 

HistoricProcessInstance vs. HistoricActivityInstance

bcymet
Champ in-the-making
Champ in-the-making
Hi,

I am writing some code to query some activiti history.

I need to know the end event for the last execution of a specific process with a specific variable value.

I currently have this code:

List<HistoricProcessInstance> historicProcessInstanceList = historyService.createHistoricProcessInstanceQuery().processDefinitionKey("websalesWorkflow")                                                                                       .variableValueEquals("username", execute.getVariable("customer"))                                                                                          .orderByProcessInstanceEndTime().desc()                                                            .list();
      
HistoricProcessInstance lastWebsalesWorkflow = (HistoricProcessInstance)historicProcessInstanceList.get(0);
System.out.println("Last End Event" + lastWebsalesWorkflow.getEndActivityId());


getEndActivityId() gives me exactly what I need however it as been deprecated. The javadocs say to use HistoricActivityInstance to find the end activity id.

I am having a little trouble figuring out how to do that. My first hurdle seems to be how to set the processDefinitionKey (as opposed to the processDefinitionId) on a HistoricActivityInstance.

Is there a way to get the latest processDefinitionId for a given processDefinitionKey?

I will also need to get the value of a specific variable for the process if I find a process with the correct end activity id, which the HistoricProcessInstance also allows me to do.

Am I going about this the right way? An example of how to use HistoricActivityInstance would be appreciated.

Thanks,

Bram

1 REPLY 1

jbarrez
Star Contributor
Star Contributor
You can find the process definition id of a process definition by doing first a ProcessDefinitionQuery (on the repositoryService) and ask for the latest().

You can order the list of activity instances by date, and only get the last element to know which element was visited last.