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="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:activiti="http://activiti.org/bpmn" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test">
   <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">
         <extensionElements>
            <activiti:field name="firstName" stringValue="Bob"/>
         </extensionElements>
      </serviceTask>
            
      <sequenceFlow id="flow2" name="" sourceRef="servicetask1" targetRef="endevent1"/>

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

package za.co.conclude.workflow;

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;
    }
}



package za.co.conclude.workflow;

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

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

    public void sayHello()
    {
        System.out.println("Hello");
    }

    public void sayGoodbye()
    {
        System.out.println("Goodbye");
    }
}

This code is wired with Spring.

Thanks a bunch in advance.

Outcomes