# Get user who completed a specific task programmatically

**URL:** <https://forum.flowable.org/t/get-user-who-completed-a-specific-task-programmatically/1373>\
**Category:** Flowable Engine\
**Created:** [December 27, 2017, 9:16pm UTC](https://forum.flowable.org/t/get-user-who-completed-a-specific-task-programmatically/1373 "2017-12-27T21:16:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![seq2seq](https://avatars.discourse-cdn.com/v4/letter/s/0ea827/32.png) [@seq2seq](https://forum.flowable.org/u/seq2seq)\
**Post date:** [December 27, 2017, 9:16pm UTC](https://forum.flowable.org/t/get-user-who-completed-a-specific-task-programmatically/1373/1 "2017-12-27T21:16:11Z")

</div>

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.

Thanks.

---

<div class="post-metadata">

**Author:** ![arpit.agrawal](https://avatars.discourse-cdn.com/v4/letter/a/c5a1d2/32.png) [@arpit.agrawal](https://forum.flowable.org/u/arpit.agrawal)\
**Post date:** [December 28, 2017, 7:05am UTC](https://forum.flowable.org/t/get-user-who-completed-a-specific-task-programmatically/1373/2 "2017-12-28T07:05:08Z")

</div>

Hi,

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--](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--](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.

Thank You,  
Arpit
