Getting the Initiator of a Process within a JavaDelegate

519 views
Skip to first unread message

zero...@gmail.com

unread,
Feb 15, 2016, 3:30:16 AM2/15/16
to camunda BPM users
Hey Guys,

I`m currently trying to get the initiator of a Process.

I saw the following posts:
https://app.camunda.com/jira/browse/CAM-763?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel

https://groups.google.com/forum/#!searchin/camunda-bpm-users/initiator/camunda-bpm-users/rLOlf7-sxYc/-yuYcZSfxnQJ

https://groups.google.com/forum/#!searchin/camunda-bpm-users/initiator/camunda-bpm-users/raYWWjZhuuk/JjFaZY1y6_kJ

Futhermore I tried a lot of potential solutions, but nothing works.
I tried to start the processes with the delegate via the Tasklist (7.4. and 7.5-alpha1) and JavaCode within the eclipse modeller (UnitTest).

Can You give me some advise please?

Sebastian Menski

unread,
Feb 15, 2016, 4:12:49 AM2/15/16
to camunda BPM users, zero...@gmail.com
Hi,

if a process is started with an authenticated user, ie. if you are logged in in the tasklist, the startUserId of the historic process instances should be set. You
can get it either by the Java API [1] or the REST API [2]. Is this not working for you?

Cheers,
Sebastian

zero...@gmail.com

unread,
Feb 15, 2016, 4:49:10 AM2/15/16
to camunda BPM users, zero...@gmail.com
Hi,

thank You for the fast reply. This looks like the solution for my problem. Can You tell me how I can get the HistoricProcessInstace in my JavaDelegate?


I tried it the following way:

public void execute(DelegateExecution execution) throws Exception {
...

HistoricProcessInstance historicProcessInstance = execution.getProcessEngineServices().getHistoryService()
.createHistoricProcessInstanceQuery().processInstanceId(execution.getProcessInstance().getId())
.singleResult();
...
}

Cheers,
Christian

but the historicProcessInstance is null

Sebastian Menski

unread,
Feb 15, 2016, 5:08:11 AM2/15/16
to camunda BPM users, zero...@gmail.com
Hi,

the historic process instance will only be available after the first wait state was reached. Otherwise the transaction will not be commited. If your Java Delegate
is called before any wait state is reached, ie it is synchronous called after the process was started, you could get the authenticated user directly from the command context:

public void execute(DelegateExecution execution) throws Exception {
 
 
String userId = Context.getCommandContext().getAuthenticatedUserId();
}

Does this work for you?

Cheers,
Sebastian

zero...@gmail.com

unread,
Feb 15, 2016, 5:16:20 AM2/15/16
to camunda BPM users, zero...@gmail.com
Yes, this works perfectly. Thank You!

Cheers,
Christian

Reply all
Reply to author
Forward
0 new messages