find task id by process instance

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

find task id by process instance

I'm creating a task like this,

ProcessInstance processInstance = runtimeService
.startProcessInstanceByKey(ApplicationConstants.POST_APPROVAL_WORKFLOW_NAME, variablesMap);

I want to assign the owner for this, how can I do it.

If not, is it possible to find taskId from this then I can use taskService.setOwner.

Please help me with this.

1 Reply
gdharley
Intermediate

Re: find task id by process instance

Ok, obviously you are new to Activiti and workflow in general.
You are not directly creating a task, rather, you are creating a process instance based on the workflow definition ApplicationConstants.POST_APPROVAL_WORKFLOW_NAME.

This process instance may include user tasks which show up over time.

To retrieve all current tasks for a given process instance you can use the TaskService to retrieve the tasks from the process instance ID returned by your start command.

Once you have the process Instance:

List<Task> tasks = taskService.createTaskQuery().processInstanceId(pid).list()

This will return a list of tasks.

More details can be found in the Java API here.

Cheers,
greg

bp3‌