cancel
Showing results for 
Search instead for 
Did you mean: 

How to pass a variable from one java service task to another

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

Can Anyone please tell me how do i pass a variable form one service task to another.
Following is my bpmn20.xml file
<process id="process" isExecutable="true">
    <startEvent id="sid-5FC149C0-7879-4862-B61B-4F9E42EEA903"/>
   
    <serviceTask id="sid-C911DB7F-5A82-49EE-92E6-21BD24C37A0F"  name="Number1" activiti:exclusive="false" activiti:class="com.FirstNumberTask" />
   
   
    <sequenceFlow id="sid-9E3EB3DD-07B9-453D-8DA3-CA3A9490CBAE" sourceRef="sid-5FC149C0-7879-4862-B61B-4F9E42EEA903" targetRef="sid-C911DB7F-5A82-49EE-92E6-21BD24C37A0F"/>
    <serviceTask id="sid-7C471866-C110-48D1-8704-3F2DBE9963DB" name="Number2" activiti:exclusive="false" activiti:class="com.SecondNumberTask" />
    <sequenceFlow id="sid-0B941981-9EF1-4C71-BAD5-9A65D43FAFCD" sourceRef="sid-C911DB7F-5A82-49EE-92E6-21BD24C37A0F" targetRef="sid-7C471866-C110-48D1-8704-3F2DBE9963DB"/>
   ……………

I need to pass a number from first task to second task.I tried using the setVariable and getVariable method ,but i am getting a null pointer exception.

For eg:

I set a variable number1 in the first task using execution.setVariable(number1,"2") ,method.When I try to retrieve the number1's value  in my second task I am getting a Null Pointer Exception.I am new to Activiti Framework,Can anybody please help me?Thank you in advance
4 REPLIES 4

raaj1
Champ in-the-making
Champ in-the-making
sorry about the mistake followins is my BPM20.xml entry
<code>
<process id="process" isExecutable="true">
    <startEvent id="sid-5FC149C0-7879-4862-B61B-4F9E42EEA903"/>
   
    <serviceTask id="sid-C911DB7F-5A82-49EE-92E6-21BD24C37A0F"  name="Number1" activiti:exclusive="false" activiti:class="com.FirstNumberTask" />
   
   
    <sequenceFlow id="sid-9E3EB3DD-07B9-453D-8DA3-CA3A9490CBAE" sourceRef="sid-5FC149C0-7879-4862-B61B-4F9E42EEA903" targetRef="sid-C911DB7F-5A82-49EE-92E6-21BD24C37A0F"/>
    <serviceTask id="sid-7C471866-C110-48D1-8704-3F2DBE9963DB" name="Number2" activiti:exclusive="false" activiti:class="com.SecondNumberTask" />
    <sequenceFlow id="sid-0B941981-9EF1-4C71-BAD5-9A65D43FAFCD" sourceRef="sid-C911DB7F-5A82-49EE-92E6-21BD24C37A0F" targetRef="sid-7C471866-C110-48D1-8704-3F2DBE9963DB"/>
……………

</code>

trademak
Star Contributor
Star Contributor
Hi,

This does work. Could you add all the Java code you use in your Java delegates?

Best regards,

raaj1
Champ in-the-making
Champ in-the-making
Hi trademak Thanks a lot for your timely help ,really apologise for the late reply got caught in acritical delivarable at my workplace.Yes as u said its verty simple and i was able to execute the task after i restarted my osgi container,where im deploying my task as a business process.

frederikherema1
Star Contributor
Star Contributor
Great - I presume your problem is fixed?