I want to get the processInstanceInfo from the global listener when I start the process
But ,It’s null.
ProcessInstanceId is not null.
@Slf4j
@Component
public class CamundaEventListeners {
@Resource
RuntimeService runtimeService;
@EventListener
public void onExecutionEvent(DelegateExecution executionDelegate) {
//it's null
ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(executionDelegate.getProcessInstanceId()).singleResult();
log.info("Handling mutable DelegateExecution:{},{}", executionDelegate.getCurrentActivityName(),executionDelegate.getCurrentActivityId());
}
}
Hello @Luka.xiaofeng ,
do you have a wait state before? If not, the process instance is not yet saved to the database and cannot be queried.
By setting async before on a start event, you will get your process instance saved to the database immediately.
@Niall this one is for you 
1 Like
Thanks. @jonathan.lukas
I’ve set async before on a start event.
but execution listeners will not be invoked synchronously?
Hello @Luka.xiaofeng ,
indeed, ExecutionListeners are invoked synchronously.
Did the async before on start event solve the problem?
Jonathan
Hi @jonathan.lukas
I would probably solve the problem from a business perspective.
Hi @Luka.xiaofeng ,
what would that mean for you?
Jonathan
HI. @jonathan.lukas
Maybe I can use variables .
I just want to get the processinstance startuserId in listener.
Hello @Luka.xiaofeng ,
for this, there is a field in the start event called Initiator. By entering a value there, the userId of the user starting the process instance will be mapped to this variable.
This will do the trick.
Jonathan
1 Like
HI. @jonathan.lukas
It’s solved my problem.
Thanks.
1 Like
Hello Jonathan,
i have the similar problem im ExecutionListener on ServiceTask : that is next after Start Event:
Cannot fetch a ProccessInstance for processInstanceId by std. Query:
private ProcessInstance getProcessInstanceForId(String processInstanceId) {
return runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult(); // .active() ??
}
// because it is not persisted
PROBLEM-1:
-
if I don’t use a “before” : it gets Null ProcessInstance for processInstanceId in ExecutionListener
-
if I use a “before” of SeviceTask : Process token it is hanging without execution of serviceTask !
before + after should : persist before and go towards User Task. Am I right ?
What is a problem ?
PROBLEM-2:
Timer does not fire
TA_Timer_Test.bpmn (17.0 KB)
1 Like
problem solved !!! It war a wrong property in application.yaml:
job-execution:
enabled: false
correct config for spring boot are:
camunda:
bpm:
admin-user:
id: demo
password: demo
lastName: DemoAdmin
filter:
create: All Tasks
job-execution:
enabled: true
default-number-of-retries: 3
- Execution Listener + Timer requires System Threads (Camunda Jobs).
- But it is also important to set in start event “before” to persist a state (ProcessInstance) to camunda DB !
1 Like
Glad you found the solution to your problem!
In the future, please avoid reviving old threads and instead post a new thread for your problem. This helps everything stay organized for any future readers. Thank you!