Get HistoricProcessInstance in PROCESS_CREATED event

I have ActivitiEventListener, where I’m checking PROCESS_CREATED event. I need to have both ProcessInstance (which I have from entity from event) and HistoricProcessInstance. Problem is, if i do query to search for HistoricProcessInstance with id of ProcessInstance i get null. It looks like this event is sent before commiting historic process instance to DB. Is any other way to get it somehow from event listener?

Btw. same situation is when variable is created in first task in TaskListener on start - when i catch VARIABLE_CREATED and try to get ProcessInstance or HistoricProcessInstance i get nulls from queries

I have the same problem. when i catch TASK_CREATED and try to get ProcessInstance or HistoricProcessInstance i get nulls from queries, too.

In Activiti there is something called Context from which you can get CommandContext with static method and from there you can get entity managers containing all entities that was created before commiting to DB. I don’t know, however if it’s still possible to get it in same wayFlowable 6

Hi, oszust002 I get a trick accordding to your comment. when catch TASK_CREATED:

%E5%BE%AE%E4%BF%A1%E6%88%AA%E5%9B%BE_20181011214914

this line is point.
ProcessInstance pi = ExecutionHelper.getProcessInstanceExecution(task.getProcessInstanceId());

good luck…:grinning:

What @oszust002 was referring to is the CommandContextUtil from which you can get access to the ExecutionEntityManager via CommandContextUtil.getExecutionEntityManager and then do CommandContextUtil.getExecutionEntityManager(task.getProcessInstnaceId())

Cheers,
Filip

1 Like