AnsweredAssumed Answered

Form properties are not getting archived- submitTaskFormData

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

I have a simple workflow with some form property. I am trying to create a process instance and submit the task form data using a java program as below. Everything seems to work fine except for the fact that, the form properties are not getting archived even when I submit my form using submitTaskFormData. Can someone please let me know where I am wrong?

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.activiti.engine.FormService;
import org.activiti.engine.HistoryService;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngineConfiguration;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.form.FormProperty;
import org.activiti.engine.form.TaskFormData;
import org.activiti.engine.impl.history.HistoryLevel;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.repository.ProcessDefinition;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.eclipse.jetty.security.IdentityService;

public class TestActiviti {
   static HistoryService historyService;

   public static void main(String[] args) {
      Map<String, String> properties = new HashMap<String, String>();
      Map<String, String> map = new HashMap<String, String>();
      map.put("true", "Yes");
      map.put("false", "No");

      // Create Activiti process engine
      ProcessEngine processEngine = ProcessEngineConfiguration
            .createStandaloneProcessEngineConfiguration()
            .setHistory(HistoryLevel.AUDIT.getKey())
            .setDatabaseSchemaUpdate(
                  ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE)
            .setJdbcUrl("jdbc:h2:tcp://localhost/activiti1")
            .setJobExecutorActivate(true).buildProcessEngine();

      
      RuntimeService runtimeService = processEngine.getRuntimeService();

      Map<String, Object> variables = new HashMap<String, Object>();
      variables.put("user", "fozzie");
      variables.put("imageName", "mule2.jpg");
      variables.put("description", "Invoking Activiti from Java Program");

      org.activiti.engine.IdentityService identityService = processEngine
            .getIdentityService();

   

      try {
         identityService.setAuthenticatedUserId("fozzie");
         runtimeService.startProcessInstanceByKey("SimplePictureRequest",
               variables);

         TaskService taskService = processEngine.getTaskService();

         List<Task> tasks1 = taskService.createTaskQuery()
               .taskAssignee("fozzie").list();

         taskService.setOwner(tasks1.get(0).getId(), "fozzie");

      } finally {
         ProcessDefinition definition = processEngine.getRepositoryService()
               .createProcessDefinitionQuery()
               .processDefinitionKey("SimplePictureRequest")
               .singleResult();

         FormService formService = processEngine.getFormService();
         TaskService taskService = processEngine.getTaskService();

      

         List<Task> tasks1 = taskService.createTaskQuery()
               .taskAssignee("fozzie").list();

         taskService.setOwner(tasks1.get(0).getId(), "fozzie");

         for (Task task1 : tasks1) {
            task1.setDescription("trsyt");

            TaskFormData formData = formService.getTaskFormData(task1
                  .getId());
            
            properties = new HashMap<String, String>();
            properties.put("approvalFlag", formData.getFormProperties()
                  .get(0).getValue());
            properties.put("initiatorName", formData.getFormProperties()
                  .get(1).getValue());
            properties.put("descriptionValue", formData.getFormProperties()
                  .get(2).getValue());
            properties.put("userName", formData.getFormProperties().get(3)
                  .getValue());
            properties.put("imageName", formData.getFormProperties().get(4)
                  .getValue());
            properties.put("approvalConfirmed", "false");
            
            task1.setOwner("fozzie");
            formService.submitTaskFormData(task1.getId(), properties);
            identityService.setAuthenticatedUserId(null);
         }

      }

   }
}

Outcomes