cancel
Showing results for 
Search instead for 
Did you mean: 

Pass an object between two tasks in an activiti process

akashraveendran
Champ in-the-making
Champ in-the-making
Hi all,

In my bpmn I have two service tasks, both of them are functions to call my service class functions.
The below is my bpmn file code.

   <serviceTask id="updateContact" activiti:expression="#{printer.updateContact()}" />
   <sequenceFlow id="flow3" sourceRef="updateContact" targetRef="readContact" />
   <serviceTask id="readContact" activiti:expression="#{printer.readContact()}" />

The printer variable inside expression is an object of my class Printer which contains updateContact() and readContact() functions. Now what I want is to pass an object from updateContact serviceTask to readContact serviceTask. I saw examples of passing objects to functions using delegate but I want to know if we can pass an object between two serviceTasks? If yes, then how? I am new to Activiti so please help me out with this.
1 REPLY 1

hari
Star Contributor
Star Contributor
Hi Akash,

I am a bit confused with your description. A service task must be a class and not a method. A service task must implement JavaDelegate and you will get an empty method from that interface which is execute method. Now the code you write here in the execute method will work when the flow reaches this service task.

With the below solution now I am assuming you will create 2 classes called UpdateContact and ReadContact which implements JavaDelegate.  Now you will need to know how you can pass an object from one service task to the other.

<code>
public class UpdateContact implements JavaDelegate{
    public void execute(DelegateExecution execution) throws Exception {
        Printer myPrinterObject = new Printer();
        execution.setVariable("MyPrinterObject",myPrinterObject);
    }
}
</code>

Now in your ReadContact class, use the below code to read your custom object.

<code>
public class ReadContact implements JavaDelegate{
    public void execute(DelegateExecution execution) throws Exception {
        Printer myPrinterObject = (Printer) execution.getVariable("MyPrinterObject");
    }
}
</code>