AnsweredAssumed Answered

How to persist (archive) user task form property data?

Question asked by bbarani on Feb 28, 2013
Latest reply on Mar 1, 2013 by bbarani
Hi,

I am trying to archive the task along with custom form properties.

Please find below the user task… I am calling the archive service task (java class) once the user selects one of the enum value (Yes or No).

<userTask id="confirmApproval" name="Approve the picture request"
         activiti:candidateUsers="${user}" activiti:assignee="${user}">
         <extensionElements>

            <activiti:formProperty id="initiator" name="Initiator:"
               type="string" />

            <activiti:formProperty id="approvalConfirmed"
               name="approvalConfirmed" type="enum" required="true">
               <activiti:value id="true" name="Yes"></activiti:value>
               <activiti:value id="false" name="No"></activiti:value>
            </activiti:formProperty>
         </extensionElements>
      </userTask>

Java Class:

public class ArchiveTask implements org.activiti.engine.delegate.JavaDelegate

{
   public void execute(DelegateExecution execution) throws Exception {
      Map<String, String> properties = new HashMap<String, String>();

      String assigneeName = (String) execution.getVariable("user");
      boolean approval = (Boolean) execution.getVariable("needsApproval");
      TaskService taskService = execution.getEngineServices()
            .getTaskService();
      List<Task> tasks = taskService.createTaskQuery()
            .taskAssignee(assigneeName).list();
      for (Task task : tasks) {
         task.setOwner(assigneeName);

      }
      
       ProcessDefinition definition = execution.getEngineServices().getRepositoryService()
                  .createProcessDefinitionQuery().processDefinitionKey("pictureRequestNew").singleResult();
      
      FormService formService = execution.getEngineServices()
            .getFormService();
      
         List<FormProperty> formList = formService.getStartFormData(definition.getId()).getFormProperties();
            
         System.out.println(formList.size()+" Form List size");
         System.out.println(definition.getId()+" Definition Id ");
        
      try {
         properties = new HashMap<String, String>();
         properties.put("initiator", "kermit");
         properties.put("approvalConfirmed", "Yes");
         formService.submitTaskFormData(definition.getId(), properties);
      } catch (ActivitiException e) {

      }


   }
}

For some reason my formList size is always 0, can someone let me know what I am doing wrong?

Thanks,
Barani

Outcomes