JBoss Community

Re: How does a sub-process work?

created by Esteban Aliverti in jBPM - View the full discussion

Be careful! In your example, you are working with the process instance and not the session. So kcontext.getKnowledgeRuntime() will return the same StatefullKnowledgeSession in both of your processes. But, kcontext.getProcessInstance() will return different process instances of course (one is the main process and the other one is the sub-process).

From your tests I assume you are talking about process variables. Process variables only exist in the context of the process instance. So, if you want to usa a variable from your main process in your sub-process, you need to do the mappings in the reusable-subprocess node.

For example, in the test I have provided to you, I'm declaring a variable (messages) in the parent process:

 

<property id="messages" itemSubjectRef="_messagesItem"/>

 

Because I want to use this variable in my sub-process, I need to declare a variable of the same type in it:

 

<property id="internalMessages" itemSubjectRef="_internalMessagesItem"/>

 

Then, in the reusable-subprocess node (in the paren process) I need to copy the value from messages to internalMessages:

 

<dataInputAssociation>

        <sourceRef>messages</sourceRef>

        <targetRef>_5_internalMessagesInput</targetRef>

</dataInputAssociation>

 

And because I need to use the modified value of this variable in my parent process once the sub-process is finished, I also need to do an output mapping:

 

  

<dataOutputAssociation>

        <sourceRef>_5_internalMessagesOutput</sourceRef>

        <targetRef>messages</targetRef>

</dataOutputAssociation>

 

Of course you can use eclipse editor to do all these things in a more user-friendly way :)

 

Best Regards,

Reply to this message by going to Community

Start a new discussion in jBPM at Community