cancel
Showing results for 
Search instead for 
Did you mean: 

Getting the assigner name in a task

tap007
Champ in-the-making
Champ in-the-making
I am developing a vacation request template where employee (kermit) makes a leave request. The request then shows up in manager's (gonzo) task list. We will be showing the task list of gonzo by using rest call. I have to show who has sent this leave request in the task list. So basically I want to the the assignee of the previous task. The rest call I use doesn't give me this information. How can I get this using REST:
My request is:
http://localhost:8082/activiti-rest/service/runtime/tasks?assignee=gonzo

it gives me response:
{
    "data": [
        {
            "id": "11400",
            "url": "http://localhost:8082/activiti-rest/service/runtime/tasks/11400",
            "owner": null,
            "assignee": "gonzo",
            "delegationState": null,
            "name": "Handle vacation request",
            "description": "kermit would like to take 4 day(s) of vacation (Motivation: eeeee).",
            "createTime": "2014-08-21T18:34:00.943+05:30",
            "dueDate": null,
            "priority": 50,
            "suspended": false,
            "taskDefinitionKey": "handleRequest",
            "tenantId": "",
            "category": null,
            "formKey": null,
            "parentTaskId": null,
            "parentTaskUrl": null,
            "executionId": "11387",
            "executionUrl": "http://localhost:8082/activiti-rest/service/runtime/executions/11387",
            "processInstanceId": "11387",
            "processInstanceUrl": "http://localhost:8082/activiti-rest/service/runtime/process-instances/11387",
            "processDefinitionId": "vacationRequest:1:11386",
            "processDefinitionUrl": "http://localhost:8082/activiti-rest/service/repository/process-definitions/vacationRequest%3A1%3A113...",
            "variables": []
        }
    ],
    "total": 1,
    "start": 0,
    "sort": "id",
    "order": "asc",
    "size": 1
}

In the response parentTaskId is coming as null. Is there some other way to achieve the same.
4 REPLIES 4

tap007
Champ in-the-making
Champ in-the-making
Just to add , in the JSON response description contains "kermit would like to take 4 day(s) of vacation (Motivation: eeeee)." but this forces developer creating template to write such information in the template. We need the framework to be capable of telling who assigned this task to the current assignee.

martin_grofcik
Confirmed Champ
Confirmed Champ
Hi,

Who has assigned this task to the current assignee can be tricky (it can be automatically generated). To get assignee of the previous task you can query history. In your special case you can use initiator (http://www.activiti.org/userguide/#bpmnStartEvents)

Regards
Martin

tap007
Champ in-the-making
Champ in-the-making
Thanks Martin. You are right in this special case it will be initiator. But I have to handle all the cases, at any point in a multi-step process I have to show who has assigned the task. To query history I will need the task ID of the previous task, how can I find the task id of the previous task.

martin_grofcik
Confirmed Champ
Confirmed Champ
Hi,

to get exact taskId you have to trace activiti events (org.activiti.engine.delegate.event.ActivitiEvent) from the history. (You can replay whole process instance to get taskId - but I think it is not necessary.)

For most of the cases processInstanceId and previous task name will be enough to get previous task assignee.
Another (more straightforward) possibility is to store previous task assignee in process instance variable. (add task listener to each usertask)

Regards
Martin