cancel
Showing results for 
Search instead for 
Did you mean: 

Getting result from service task

chillwabbitt
Champ in-the-making
Champ in-the-making
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.
2 REPLIES 2

jbarrez
Star Contributor
Star Contributor
Depends on what you want to do with your result.

With the process you posted, the process will indeed end immediately.
If you place a userTask between the serviceTask and the end, you will be able to use and query the value of your 'result' variable.

chillwabbitt
Champ in-the-making
Champ in-the-making
Thanks.
Getting started

Tags


Find what you came for

We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.