AnsweredAssumed Answered

Issues about persistence of variables

Question asked by sorinello on Jun 16, 2013
Latest reply on Jun 17, 2013 by sorinello
Hello.
I have an Activiti consistency behavior issue.
The code below (I have 2 versions) starts an Activiti Process Instance (None Start Event node). NEXT node is a UserTask node, which has a TaslkListener attached. I am NOT able to get the process variables inside the TaskListener with the FIRST version of my code (the one without MAP). Any Idea why ? Shouldn't they behave the same ?
Using second version, I can get the process variables from the TaskListener using. The same code for first version returns null:

DelegateExecution execution = delegateTask.getExecution();
System.out.println("Username " + execution.getVariable("Username"));


First Version

activiti.getProcessEngine().getRuntimeService().startProcessInstanceById(startMappingResults.get(i));
activiti.getProcessEngine().getRuntimeService().setVariable(processInstance.getId(), "Document Name", documentName);
activiti.getProcessEngine().getRuntimeService().setVariable(processInstance.getId(), "Document Space", documentSpace);
activiti.getProcessEngine().getRuntimeService().setVariable(processInstance.getId(), "Username", username);


and

Second Version

Map<String, Object> variables = new HashMap<String, Object>();
  variables.put("Document Name", documentName);
  variables.put("Document Space", documentSpace);
  variables.put("Username", username);
ProcessInstance processInstance = activiti.getProcessEngine().getRuntimeService().startProcessInstanceById(startMappingResults.get(i),variables);


I lost 2 full days until I tried starting the process instance with the Map already defined. Please, what is the difference between my 2 approaches ? Why one is working and the other is not ?

Outcomes