org.jbpm.api.ProcessInstance processInstanceById = executionService.findProcessInstanceById(pi.getInternalId());
String processDefinitionId;
if (processInstanceById == null) { //look in history service
HistoryProcessInstanceQuery historyProcessInstanceQuery = processEngine.getHistoryService()
.createHistoryProcessInstanceQuery().processInstanceId(pi.getInternalId());
HistoryProcessInstance historyProcessInstance = historyProcessInstanceQuery.uniqueResult();
processDefinitionId = historyProcessInstance.getProcessDefinitionId();
} else {
processDefinitionId = processInstanceById.getProcessDefinitionId();
}
List<ProcessDefinition> latestList = service.createProcessDefinitionQuery()