private byte[] fetchProcessResource(ProcessInstance pi, String resourceName) {
ProcessEngine processEngine = getProcessEngine(ProcessToolContext.Util.getThreadProcessToolContext());
RepositoryService service = processEngine.getRepositoryService();
ExecutionService executionService = processEngine.getExecutionService();
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();