is this posssible to get details of completed task using processinstance id?

cancel
Showing results for 
Search instead for 
Did you mean: 
jigpra
Member II

is this posssible to get details of completed task using processinstance id?

I want to get details of all finished task  with the data using process instance id.
how can i?
is this possible to get request data after completed flow of bpm?

5 Replies
nikmenke
Active Member II

Re: is this posssible to get details of completed task using processinstance id?

Hi,

have you tried something like this?:

historyService.createHistoricTaskInstanceQuery()

.finished()

.includeProcessVariables()

.includeTaskLocalVariables()

.processInstanceId(processInstanceId)

.list()

jigpra
Member II

Re: is this posssible to get details of completed task using processinstance id?

Hello Niklas Menke
Greetings,

Thanks for Quick Response..

currently i getting processinstance id  for myuser using below code:
List<HistoricProcessInstance> historicProcessInstances = this.historyService.createHistoricProcessInstanceQuery().finished().startedBy(userid).list();

for(int i=0;i<historicProcessInstances.size();i++){

List<Task> taskList = this.taskService.createTaskQuery().processInstanceId(historicProcessInstances.get(i).getId()).orderByTaskCreateTime().desc().list();
for(Task task : taskList){
                        ProcessDefinition processDefinition = this.repositoryService.getProcessDefinition(task.getProcessDefinitionId());
                        TaskResponse taskResponse = new TaskResponse(task);

}

}

this code is working if task is pending or not complete with change in
List<HistoricProcessInstance> historicProcessInstances = this.historyService.createHistoricProcessInstanceQuery().unfinished().startedBy(userid).list();

i replace my code to you suggest code but for completed task not working in my case to get task response.
in my case i want task response details of that completed task
Is this Possible to get task response after task completed?


Another question i have for related task response.

after task completed the data stored in task response as do in unfinished task?

or

in future i want to get of details earlier task which is already completed.does this data stored in task response at any place which i can get when i required?

Thank you.

thuynh
Established Member II

Re: is this posssible to get details of completed task using processinstance id?

Hi jigar Prajapati ,

I want to get details of all finished task  with the data using process instance id.

What kind of data do you want to retrieve from completed tasks? If possible, could you please describe your business use case more?

Anyway, Activiti provide History features which allow you to retrieve completed tasks details. Please have a look at the documentation.

- REST API for HistoricDetail: Activiti User Guide 

- Java: Activiti User Guide  

Hope this helps

Thong

nikmenke
Active Member II

Re: is this posssible to get details of completed task using processinstance id?

Hi,

everytime you work with finished tasks or processinstances you have to query the history. So It is the HistoricTaskInstanceResponse you would need. In the history are all variables, all tasks and all process instances stored. For both, running and completed instances and tasks.

for(int i=0;i<historicProcessInstances.size();i++){

List<HistoricTaskInstance> taskList = this.historyService.createHistoricTaskInstanceQuery().processInstanceId(historicProcessInstances.get(i).getId()).orderByTaskCreateTime().desc().list();
for(HistoricTaskInstance task : taskList){
                        ProcessDefinition processDefinition = this.repositoryService.getProcessDefinition(task.getProcessDefinitionId());
                        HistoricTaskInstanceRespone taskResponse = new TaskResponse();

                        taskResponse.setId(task.getId());

                        ...

                        ...

               

}

 

}

But if you are working with rest why don't you just use following call to get the historic tasks?

GET history/historic-task-instances

Hope this helps,

Niklas

jigpra
Member II

Re: is this posssible to get details of completed task using processinstance id?

Hello ‌  and
I use your code to get details of that task/request which is completed.
but unfortunately my further process is to get details of task using process instance id.
i think when workflow completed the task response for that process id will deleted
and currently i want  to get task response of completed task.
your code retrieve the information for historicalinsstance but in further  i use  that historical instance id to get task details using taskservice when task is completed .


here is following screenshot of my localhost with postman
when request completed /end event complted

in above screen shot i use above method which i discussed earlier in reply
the data is in proper manner as string for my output
i retrieve this info using taskservice and processinsatnce id
if task is completed (ended) then retrieve me null task
else retrieve me data of that task.

Thank you.