cancel
Showing results for 
Search instead for 
Did you mean: 

TaskFormData is null inside complete taskListener

yourboogieman
Champ in-the-making
Champ in-the-making
I have a user task for which I am invoking a task listener when the task completes:


        <userTask id="getDoorInfo" name="Get door info" activiti:exclusive="false">
            <extensionElements>
                <activiti:formProperty id="doorColor" name="Door color" variable="doorColor" readable="true" type="string" required="true" />
                <activiti:taskListener event="complete" expression="${formCollectionBuilder.addForm(execution)}" />
            </extensionElements>
            <potentialOwner>
                <resourceAssignmentExpression>
                    <formalExpression>management</formalExpression>
                </resourceAssignmentExpression>
            </potentialOwner>
            <multiInstanceLoopCharacteristics isSequential="true">
                <loopCardinality>${numDoors}</loopCardinality>
            </multiInstanceLoopCharacteristics>
        </userTask>

The code which is being invoked by the listener is:

[java]
public class FormCollectionBuilder {
   
   public void addForm(DelegateExecution execution) throws Exception {
                final String taskId = execution.getCurrentActivityId();
      final String taskFormCollId = taskId + "FormCollection";
      @SuppressWarnings("unchecked")
      List<List<FormProperty>> forms =
         (List<List<FormProperty>>) execution.getVariable(taskFormCollId);
      if (forms == null) {
         forms = new ArrayList<List<FormProperty>>();
         execution.setVariable(taskFormCollId, forms);
      }
                TaskFormData formData = execution.getEngineServices().getFormService().getTaskFormData(taskId);
      final List<FormProperty> formProps = formData.getFormProperties();
      forms.add(formProps);
   }

}
[/java]

The issue I am having is that the call to getTaskFormData is returning null.  Looking in my debugger at runtime, the task ID is "getDoorInfo", which is the correct one, so I can't figure out why this is returning null.  Any idea what I'm doing wrong?
2 REPLIES 2

trademak
Star Contributor
Star Contributor
This is not the correct task id, you are using the task definition key. For a task listener it would be better to use a DelegateTask as input parameter and get the task id from there. You can use the following expression for that:

${formCollectionBuilder.addForm(task)}

Best regards,

yourboogieman
Champ in-the-making
Champ in-the-making
Yep, worked like a charm.  Thanks, you rock! Smiley Very Happy