Which editor are you using?
In jbpm5 you have 2 different types of sub-processes: embedded sub-processes and reusable sub-processes. You case is the later.
Please take a look at this test that uses reusable sub-processes:
thank you! I solved the problem with your example
Great! Please mark this post as Resolved, or answered (I don't remember the right term). By doing this you will save some time to a lot of people in your same situation. Best Regards,
I can only modify the title and write SOLVED, because I can't modify the discussion in a question!
Hi! I have another question about Sub-processes;
In the sub-process I store some objects in the ksession; I would like to use the object ksession of the sub-process in the main process; in what way can I pass a parameter from sub-process to the main process?
I thought to create 2 variables: one in the main process called ksession (and type org.drools.runtime.StatefulKnowledgeSession), and the other variable in the sub-process called ksessionInternal (type org.drools.runtime.StatefulKnowledgeSession); these 2 variables are the "parameter out mapping" of the node sub-process... is right?
the problem is: in what way can I pass the ksessionInternal to the ksession variable?
thank you very much!
In JBPM5 you have two different scopes: one are process' variables and the other is ksession (shared among all the processes running in it). In the case of variables, you need to map the input and output variables of your sub-process using the editor for example. So If you want to use a variable from the main process in the sub-process, you need to define an input parameter in the sub-process and do the corresponding mapping in the reusable-subprocess node of your main process. If your sub-process modifies the variable or creates a new one and you want to use it in the main process, you need to map (again, in the reusable-subprocss node) the output variable from the sub-process to a variable in the main process. In the case of embedded sub-processes, you don't need to do these mappings, because both processes are in the same "context". If you are storing variables in you session (using insert() for example), you don need to do anything special. You don't even need to pass the ksession from the main process to the sub-process. Both processes could reach the same ksession using the "magic" variable kcontext: kcontext.getKnowledgeRuntime() Best Regards,
ok, I undestard the difference... so now I need an embedded sub process node, because I need to use the ksession(where are stored object that I must use in the main process).
on the guide there isn't any example of embedded sub-process... do you have some example??
thank you very much!
The ksession is shared among all the processes and sub-processes no matter the sub-process type. So what you get in your main process when you invoke kcontext.getKnowledgeRuntime() is the same object that you get in a (reusable or embedded) sub-process when you invoke kcontext.getKnowledgeRuntime(). If you still want to see a simple example using embedded sub-process you can take a look at the same example project I have provided.
Hi Esteban, I'm sorry to contradict you, but the ksession is not the same in main and sub-process.
I take a test with a variable and the resul is different
org.drools.runtime.process.WorkflowProcessInstance process = (org.drools.runtime.process.WorkflowProcessInstance)kcontext.getProcessInstance();
System.out.println("Risultato Processo Principale: "+process.getVariable("risultato"));
.... so this means that in the main process I can't use the ksession on the sub-process.
at this point... what is the point of using of a sub-process?? is not very useful!!!
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:
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:
Of course you can use eclipse editor to do all these things in a more user-friendly way
Thank you I used the sub-process and I solved my problem