cancel
Showing results for 
Search instead for 
Did you mean: 

Adding attributes to the user task

bluerain
Champ in-the-making
Champ in-the-making
I need to create user tasks along with storing some attributes related to my business like based on purchase order the task are created so need to store the purchaseOrderId along with the task so that it could be used a search criteria.

Can anybody suggest me in achieving this?

Thanks
3 REPLIES 3

frederikherema1
Star Contributor
Star Contributor
You can use task-local variables for this. Using the TaskQuery, you can ask for all tasks with a variable set the the given value:

taskService.createTaskQuery().taskVariableValueEquals("purchaseOrderId", "12345").list();

bluerain
Champ in-the-making
Champ in-the-making
how do i set the variables in the class MyAssignmentHandler

<userTask id="task1" name="My task" >
  <extensionElements>
    <activiti:taskListener event="create" class="org.activiti.MyAssignmentHandler" />
  </extensionElements>
</userTask>

@Override
public void notify(DelegateTask delegateTask) {
                delegateTask.setDescription("Purchase Order Task");
  delegateTask.createVariableLocal("NumberAttribute1",delegateTask.getExecution().getVariable("puchaseOrderId"));
}

But this doesnt seem to work because my test case is not able to retrieve the task based on the variable set.

List<Task> taskList = taskService.createTaskQuery()//.list();
    .taskVariableValueEquals("NumberAttribute1", purchaseOrderId).list();

This does not give me any results.
But if I do
List<Task> taskList = taskService.createTaskQuery().list();
It gives me the task created…
Any advice is welcome??

frederikherema1
Star Contributor
Star Contributor
Hi, you should use delegateTask.setVariableLocal(). Also, make sure the type of the Object set in 'setVariableLocal' is the same type as the one you use for querying (eg. Long).