AnsweredAssumed Answered

How to retrieve the the return value of the last serviceTask

Question asked by petercahyadi on Feb 23, 2012
Latest reply on Jul 15, 2016 by dananemanoj
Hi, is there a way to retrieve the return value of the serviceTask at the end of the process ?

My BPMN file is as below
<definitions id="definitions" targetNamespace=""
   xmlns:activiti="" xmlns="">
   <process id="testProcess" name="Test process">
      <startEvent id="theStart" />
      <sequenceFlow id='flow1' sourceRef='theStart' targetRef='javaService' />
      <serviceTask id="javaService" name="My Java Service Task"
         activiti:resultVariableName="myResult" />
      <sequenceFlow id='flow2' sourceRef='javaService'
         targetRef='theEnd' />
      <endEvent id="theEnd" />

And my Java serviceTask is as below

public class MyServiceTask {
   public String execute(String name) throws Exception {
      List<MyTable> myTables = myTableMapper.selectByExample(null);
      int maxId = -1;
      for (MyTable myTable : myTables) {
         maxId = maxId < myTable.getId() ? myTable.getId() : maxId;

      MyTable newMyTable = new MyTable();
      newMyTable.setId(maxId + 1);

      return "Halo " + name + " !";

   private MyTableMapper myTableMapper;


and here is my main code, which is the one who started the process.

Map<String, Object> input = new HashMap<String, Object>();
input.put("name", "Peter");
ProcessInstance pi = runtimeService.startProcessInstanceByKey("testProcess", input);

i've been trying to retrieve the return value of the java service task, after the startProcessInstanceByKey() finishes executing. but no luck so far, any suggestion on how to do this ?