cancel
Showing results for 
Search instead for 
Did you mean: 

Process Instance Variables

michael_eyre
Champ in-the-making
Champ in-the-making
I am working on an integration with Activiti and a java REST application.  The application is designed to receive JSON data and start the specified process instance by the key.  What I want to do is to get the list of starter variables for the process instance to verify all of the necessary values are present before starting the process instance.  If there is anything missing, I can send an error message back in the response.

I have found classes to query existing process instances, but I have not found a way to get what variables need to be populated at the launch of the process.

Here is my current test code:

   public static String create (String processName, JSONObject inputData) {
      
      ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
      
      // Get Activiti services
      RuntimeService runtimeService = processEngine.getRuntimeService();
      Map<String, Object> variables = new HashMap<String, Object>();
      for (String key:inputData.getJSONObject("data").keySet()) {
         System.out.println("Data Key:" + key);
         variables.put(key, inputData.getJSONObject("data").get(key));
      }
      
      RepositoryService repositoryService = processEngine.getRepositoryService();
      DeploymentQuery deploymentQuery = repositoryService.createDeploymentQuery();
      deploymentQuery.processDefinitionKey(processName);
      long deploymentCount = deploymentQuery.count();
      Deployment testDeployment = deploymentQuery.singleResult();
      log.info("Deployment ID = " + testDeployment.getId());
      
      variables.put("startDate", new Date());
      variables.put("employeeName", "Test Cloud Logic");
      
      ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(processName, variables);
      
      log.info("Process instance ID: " + processInstance.getId());
      
      return "test";
   }


Thanks

Mike

5 REPLIES 5

martin_grofcik
Confirmed Champ
Confirmed Champ
Hi Mike.

The information about mandatory variables required at the process start is not part of the default BPMN model.
Possible solutions:
    * extend BPMN model (use extension elements)
    * use current extensions (e.g. use reference to the form and describe required variables there)
    * describe mandatory variables outside of BPMN model
Regards
Martin

michael_eyre
Champ in-the-making
Champ in-the-making
What I am looking for are what are the form properties of the start form for a process.  I am using the Vacation Request process that is part of the examples.  If I do not include all of the variables in the start form, Activiti will return a warning.  So, I want to get the list of form properties to I can verify all of the data will be populated before starting.

I think that I am on the right track with this:
<java>
  String processDefinitionId = processEngine.getRepositoryService().createProcessDefinitionQuery().processDefinitionKey(processName).latestVersion().list().get(0).getId();
     StartFormData startForm = processEngine.getFormService().getStartFormData(processDefinitionId);
     List<FormProperty> startFormProperties = startForm.getFormProperties();
</java>

The list that is returned is all of the start form properties, the field names and their type.  This appears to be what I am looking for.

The only aspect left is to find the activiti initiator variable name

martin_grofcik
Confirmed Champ
Confirmed Champ
Hi Michael,

yes, that's option 2.
initiator -> have a look org.activiti.engine.impl.bpmn.parser.handler.StartEventParseHandler#createProcessDefinitionStartEvent. could help.

Martin

michael_eyre
Champ in-the-making
Champ in-the-making
Will this give me the name of the field that the initiator variable that the data will be put in or will it give me the value that was put into the initiator variable?

martin_grofcik
Confirmed Champ
Confirmed Champ
Hi Michael,

have a look on org.activiti.engine.test.bpmn.usertask.InitiatorTest#testInitiator in Activiti source. jUnit tests are the best way to describe the behaviour.

Regards
Martin