cancel
Showing results for 
Search instead for 
Did you mean: 

Form properties are not getting archived- submitTaskFormData

bbarani
Champ in-the-making
Champ in-the-making
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);
         }

      }

   }
}
4 REPLIES 4

frederikherema1
Star Contributor
Star Contributor
The call to getFormProperties returns an EMPTY form, so these kind of commands are pointless:


formData.getFormProperties()
                  .get(0).getValue()

And what do you mean by "not being archived"? Not in history or in the runtime variables?

bbarani
Champ in-the-making
Champ in-the-making
The call to getFormProperties returns an EMPTY form, so these kind of commands are pointless:


formData.getFormProperties()
                  .get(0).getValue()

And what do you mean by "not being archived"? Not in history or in the runtime variables?


I am setting the form values (in user form) from the calling client. Approvers wont be able to modify the form values rather they will just click approve or deny.

I then try to archive the form (both approved / denied) - I want to see the form under archive tab. I see the task under archive tab but I am not able to see the form data. I got to know that I need to submit my form using submittaskformdata in order for the form values to get persisted in the tables but for some reason its not working for me..

I am able to get the value of the form using the below function.
    
     System.out.println("Task Id:" + task1.getId());
    System.out.println("Task Form ID:" + formData.getTask().getId());
   
    System.out.println(formData.getFormProperties().get(0) .getName()
    
     + formData.getFormProperties().get(0).getValue() );
     System.out.println(formData.getFormProperties().get(1) .getName()
    
     + formData.getFormProperties().get(1).getValue() );
     System.out.println(formData.getFormProperties().get(2) .getName()
    
     + formData.getFormProperties().get(2).getValue() );
     System.out.println(formData.getFormProperties().get(3) .getName()
    
    + formData.getFormProperties().get(3).getValue() );
     System.out.println(formData.getFormProperties().get(4) .getName()
     + ":" + formData.getFormProperties().get(4).getValue() );

Task Id:14911
Task Form ID:14911
Needs Approval:true
Initiator:fozzie
Description:Invoking Activiti from Java Program
User:fozzie
Image::mule2.jpg

I tried even setting static data in the form (as below) but this again just stores the task information and not the form field data (i.e. I see the tasks under archive tab but the tasks doesn't contain any of the user form property).


TaskService taskService = processEngine.getTaskService();
   List<Task> task = taskService.createTaskQuery().list();
   TaskFormData formData = null;
   for (Task tasks : task) {
    formData = formService.getTaskFormData(tasks.getId());
   }

   System.out.println(formData.getTask().getId());

   properties = new HashMap<String, String>();
   properties.put("approvalFlag", "true");
   properties.put("initiatorName", "fozzie");
   properties.put("descriptionValue", "Testing custom form");
   properties.put("userName", "barani");
   properties.put("imageName", "mule2.jpg");
   properties.put("approvalConfirmed", "true");
   formData.getTask().setDescription("testing");

   formService.submitTaskFormData(task.get(0).getId(), properties);

frederikherema1
Star Contributor
Star Contributor
The "Archived" page in explorer doesn't fetch the properties at all. Please note that the archive show HistoricTaskInstances rather than running Task instances. See HistoricTaskDetailPanel, no form-properties are added:

protected void init() {
    setSizeFull();
    addStyleName(Reindeer.LAYOUT_WHITE);
   
    this.centralLayout = new VerticalLayout();
    centralLayout.setMargin(true);
    setDetailContainer(centralLayout);
   
    initHeader();
    initDescription();
    initParentTaskLink();
    initPeopleDetails();
    initSubTasks();
    initRelatedContent();
  }

If you want explorer to show historic form-properties (using HistoricDetail), you'll have to write that functionality yourself…

bbarani
Champ in-the-making
Champ in-the-making
The "Archived" page in explorer doesn't fetch the properties at all. Please note that the archive show HistoricTaskInstances rather than running Task instances. See HistoricTaskDetailPanel, no form-properties are added:

protected void init() {
    setSizeFull();
    addStyleName(Reindeer.LAYOUT_WHITE);
   
    this.centralLayout = new VerticalLayout();
    centralLayout.setMargin(true);
    setDetailContainer(centralLayout);
   
    initHeader();
    initDescription();
    initParentTaskLink();
    initPeopleDetails();
    initSubTasks();
    initRelatedContent();
  }

If you want explorer to show historic form-properties (using HistoricDetail), you'll have to write that functionality yourself…

Thanks a lot for the clarification….