How can I get the username that completed a specific task programmatically?
In my JavaServiceTask, I have two objects: DelegateExecution and RuntimeService, but I haven’t figure out how to play with them to get a task by Id from the current process instance, and for that task, get the assignee or user who completed the task.
DelegateExecution class has a method getProcessInstanceId through which you can get the current processInstanceId of this execution (Doc : http://www.flowable.org/docs/javadocs/org/flowable/engine/delegate/DelegateExecution.html#getProcessInstanceId--). Using this processInstanceId you can use History Service to create a Historic Task Instance Query (Docs : http://www.flowable.org/docs/javadocs/org/flowable/engine/HistoryService.html#createHistoricTaskInstanceQuery--)
then you can use taskDefinitionKey you declared in flowable-modeler to find the task you are looking for. Once you have the
object of HistoricTaskInstance, you can find anything about that task like taskId, Assignee etc.
Your query might look like this :
“historyService.createHistoricTaskInstanceQuery().taskDefinitionKey(“dummyTaskKey”).singleResult()” . This will return you HistoricTaskInstance class object. Then you can use functions associated with this object to get the required things.