activityInstanceId from taskId

Given a processInstanceId of 8a6ac984-4c41-11e9-9141-5404a6dffb14
and a taskId of “myTask”

how can I get the activityInstanceId of the task?

Thans so much.

Hi @eugene,

via the REST API, perform the following request:
GET /history/activity-instance?processInstanceId=8a6ac984-4c41-11e9-9141-5404a6dffb14&activityId=myTask

Cheers,
Tassilo

1 Like

Thanks so much @tasso94

However, I was hoping I could get it via the Java API such as execution… or task…getActivityInstance();

1 Like

Hi Eugene,

what about this approach?

List<HistoricActivityInstance> activityInstances = historyService.createHistoricActivityInstanceQuery()
    .activityId("myTask")
    .processInstanceId("8a6ac984-4c41-11e9-9141-5404a6dffb14")
    .unfinished()
    .list();

Cheers,
Tassilo

Once again, thanks so much for helping @tasso94

I’m not a developer, especially Java, and find it very difficult to get my head around the various classes and their methods.

Your example above returns the correct HistoricActivityInstance object, however I need to get to the Task object.
1 I notice the activityInstanceId is null but the taskId is now the instance ID, and no longer the “myTask” string. Is that expected?
2 I also assume the taskId can be used in stead of the activityInstanceId. Am I right?
3 If so, then how can I obtain the Task object from the returned taskId?

I’ve tried to do so myself with this code:

List activityInstances = historyService.createHistoricActivityInstanceQuery().activityId(“myTask”).processInstanceId(processInstanceId).unfinished().list();

System.out.println(Thread.currentThread().getStackTrace()[1].getMethodName() + " : activityInstances : " + activityInstances);

//There should only be a single User task with the name of “myTask”, so it’s safe to use get(0)
HistoricActivityInstance singleActivityInstance = activityInstances.get(0);

String taskId = singleActivityInstance.getTaskId();

//This causes an error since the return type has to be a Task object
return taskService.createTaskQuery().getActivityInstanceId(taskId).singleResult();
return taskService.createTaskQuery().activityInstanceId(taskId).singleResult();

Do you know how I can achieve that?
Thanks so much

Have you found the method yet? please