I created two "Hello World" processes to give the subProcess nodes a whirl. I'm having trouble getting output from the subProcess back to the main process. I'm hoping someone can enlighten me on what I'm doing wrong as I can't find any documentation or examples that shed light on why mine doesn't work.
In my main process, I have the following (note that I've snipped headers, footers, and the positional x, y, height, width attributes):
... snip... <header> <variables> <variable name="name" > <type name="org.drools.process.core.datatype.impl.type.StringDataType" /> <value>World</value> </variable> <variable name="length" > <type name="org.drools.process.core.datatype.impl.type.IntegerDataType" /> <value>0</value> </variable> </variables> </header> ... snip... <subProcess id="4" name="SubHello" processId="subhello" waitForCompletion="true" > <mapping type="in" from="name" to="name" /> <mapping type="out" from="length" to="length" /> </subProcess> ... snip...
And here is the simple subhello
SubProcess, which simply takes the input and prints it out, and then gets the input length to return it back out:
... snip... <header> <variables> <variable name="name" > <type name="org.drools.process.core.datatype.impl.type.StringDataType" /> <value></value> </variable> <variable name="length" > <type name="org.drools.process.core.datatype.impl.type.IntegerDataType" /> <value></value> </variable> </variables> </header> <nodes> <start id="1" name="Start" /> <end id="2" name="End" /> <actionNode id="3" name="Action" > <action type="expression" dialect="mvel" > System.out.println(name + ", " + length + ", in SubProcess, before"); length = name.length; System.out.println(length + ", in SubProcess, after"); </action> </actionNode> </nodes> ... snip...
This is as per how I interpreted the doc and examples. The needed variables are declared on both the main process and the subprocess, then just use the subProcess in/out mapping elements to set the from and to attributes.
The problem is.... while name
got passed in to the subProcess without issue, trying to get length
back to the main process failed. The length
in the subProcess was successfully modified. But on exit, length
in the main process did not change.
What am I doing wrong? Pointers and explanations are much appreciated. Thanks.