cancel
Showing results for 
Search instead for 
Did you mean: 

Field Injection for UserTasks

prasanthnath_g
Champ in-the-making
Champ in-the-making
From the documentation, I see that field injection is supported for Service tasks. I just wanted to know if the same is supported for user tasks too. Something like this:

<userTask id="auditPhase1" name="Audit Phase 1">
   <extensionElements>
      <activiti:field name="actions" stringValue="Approve,Reject,Reprocess" />
   </extensionElements>
</userTask>


We have a requirement to show the list of tasks defined in the work flow and supported actions for each task. There are several audit tasks which are modeled as user tasks in our workflow. And each audit task can have different actions supported. For ex: Approval, rejection, Re-process data. So I just wanted to know if I can store that information in user task definition itself.

Here is how we are fetching task details:

ProcessInstance processInstance = getProcessInstance(dataId);
BpmnModel model = getBpmnModelForProcessDefinition(processInstance.getProcessDefinitionId());
List<TaskDetail> taskDetails = Lists.newArrayList();
for(Object obj : model.getMainProcess().getFlowElements()) {
   if(obj instanceof ServiceTask) {
      ServiceTask serviceTask = (ServiceTask)obj;
      taskDetails.add(new TaskDetail(serviceTask));
   } else if(obj instanceof UserTask) {
      UserTask userTask = (UserTask)obj;
      taskDetails.add(new TaskDetail(userTask));
   }
}

So now if the actions can be stored as fields in the user task definition itself, then I can fetch and store that information in the above code. Please suggest!
12 REPLIES 12

prasanthnath_g
Champ in-the-making
Champ in-the-making
I tried doing this:
<code>
<userTask id="audit1" name="Audit Phase 1" activiti:resultVariable="status" xmlns:adaequare="http://www.adaequare.com/" >
<extensionElements>
  <adaequare:field name="actions" stringValue="Approve,Reject,Reprocess" />
</extensionElements>
</userTask>
</code>

But even after this, on trying to read the user task extensionElements, extensionElements is coming as empty.

martin_grofcik
Confirmed Champ
Confirmed Champ
Could you create jUnit test for it please?
http://forums.activiti.org/content/sticky-how-write-unit-test

Regards
Martin

prasanthnath_g
Champ in-the-making
Champ in-the-making
I got a solution for this. Not sure if this is the right way to do it. But here is how I have done it:
<code>
<userTask id="audit1" name="Audit Phase 1" activiti:resultVariable="status"  xmlns:adaequare="http://www.adaequare.com" adaequare:actions="Approve,Reject,Reprocess"></userTask>
</code>

And then I accessed the attributes from code like this:
<java>
List<ExtensionAttribute> userActionAtribute = userTask.getAttributes().get(WorkflowConstants.USER_ACTIONS);
if(CollectionUtils.isNotEmpty(userActionAtribute)){
ExtensionAttribute extensionAttribute = userActionAtribute.get(0);
String value = extensionAttribute.getValue();
if(StringUtils.isNotEmpty(value)){
  taskDetail.getSupportedActions().addAll(Arrays.asList(value.split(StringConstants.COMMA)));
}
}
</java>