cancel
Showing results for 
Search instead for 
Did you mean: 

How to get the current task Id ?

pierre1
Champ in-the-making
Champ in-the-making
Hello everyone.

I'm working with Grails framework and activiti plugin.

After the call of completeTask(params), I want to get the Id of my current Task.
In my page, I send a variable taskId like this :

<g:hiddenField name="taskId" value="${params.taskId}" />

but the real value of the task Id is different to this parameter (I go to myTaskList.gsp and there is not any task with this id)

Thank you for help.
6 REPLIES 6

ashendra1
Champ in-the-making
Champ in-the-making
*bump* any suggestion

martin_grofcik
Confirmed Champ
Confirmed Champ
Hi,

May be I do not understand the problem.

In case when you complete task,  task is finished and there won't be any user task in the task service with this taskId. (there will be record in the history service - depends on the history level). Next task in the process execution (if any) is added to the task service.

Regards
Martin

ashendra1
Champ in-the-making
Champ in-the-making
Ok, let me exlplain my use case.

I have two task, task1->task2
task1 is a manual task, the form properties of this task has 1 form property named count of type long.

Now task 2 is also a manual task, the form properties of task2 uses an external form, like UserFormType. Added a renderer for this form Type. this custom form type shows a custom field which can contain n textFields, n is passed in the constructor.

The way i thought i can do this is get the count variable using
ProcessEngines.getDefaultProcessEngine().getTaskService().getVariable(taskId, "count")
but i dont know the way to get the current task id.

If there is a better way to do this then suggest. I am working over the activity-explorer.

yuryshaban
Champ in-the-making
Champ in-the-making
Seems, you have to determine, what is 'my current Task' for you?

For example: if it's just current User Task of a process with known ID - just execute something like:
(sorry, it's Java)
<code>TaskQuery query = taskService.createTaskQuery().processInstanceId(processId).includeProcessVariables();
Task theTask = query.singleResult();

Map<String, Object> processVariables = theTask.getProcessVariables();
</code>
by the way, from the variable 'theTask' you can get what you need about User Task.

Here processVariables contains … process variables Smiley Happy

In your case, after task1.completeTask(…) the process goes to task2 and stops. I.e. current task is task2 (after task1.completeTask(..)).

ashendra1
Champ in-the-making
Champ in-the-making
How can one retreive the processId in SomeFormPropertyRenderer?

frederikherema1
Star Contributor
Star Contributor
The FormPropertyRenderers don't have access to the current process-instance/task context, I'm afraid. They are designed to work independant of that context. Use the default-attribute to get hold of process-variables to use as default-values if needed… You'll have to create a custom way of rendering your form OR find some way to put the process-instance ID in a process-variable, so it's available in the FormField as default-value.