AnsweredAssumed Answered

Getting result from service task

Question asked by chillwabbitt on Jan 24, 2011
Latest reply on Jan 25, 2011 by chillwabbitt
Hi I have a really simple service task that should return a result, however being a service task it executes and ends leaving the process unavailable.
So the question would be how would I execute my code and return the result that was assigned to the variable.

<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="" xmlns:xsi="" xmlns:activiti="" typeLanguage="" expressionLanguage="" targetNamespace="">
   <process id="Main_Process" name="Main_Process">
      <startEvent id="startevent1" name="Start"/>
      <sequenceFlow id="flow1" name="" sourceRef="startevent1" targetRef="servicetask1"/>
      <serviceTask id="servicetask1" name="Service Task" activiti:expression="${printer.print()}" activiti:resultVariableName="result">
            <activiti:field name="firstName" stringValue="Bob"/>
      <sequenceFlow id="flow2" name="" sourceRef="servicetask1" targetRef="endevent1"/>

      <endEvent id="endevent1" name="End"/>


import org.activiti.engine.RuntimeService;
import org.activiti.engine.runtime.ProcessInstance;

public class ProcessHandler
    /** Field description */
    private String processID;

    /** Field description */
    private ProcessInstance processInstance;

    /** injected by Spring */
    private RuntimeService runtimeService;

    public void init(String param)
        processInstance = runtimeService.startProcessInstanceByKey("Main_Process", variables);
        processID       = processInstance.getId();
        System.out.println(runtimeService.getVariable(processID, "result").toString());

    public void setRuntimeService(RuntimeService runtimeService)
        this.runtimeService = runtimeService;


public class Printer
    public String print()
        System.out.println("Running print method");

        return ("I was set by print function");

    public void sayHello()

    public void sayGoodbye()

This code is wired with Spring.

Thanks a bunch in advance.