<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body link="#355491" alink="#4262a1" vlink="#355491" style="background: #e2e2e2; margin: 0; padding: 20px;">

<div>
        <table cellpadding="0" bgcolor="#FFFFFF" border="0" cellspacing="0" style="border: 1px solid #dadada; margin-bottom: 30px; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                <tbody>
                        <tr>

                                <td>

                                        <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border: solid 2px #ccc; background: #dadada; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                                                <tbody>
                                                        <tr>
                                                                <td bgcolor="#000000" valign="middle" height="58px" style="border-bottom: 1px solid #ccc; padding: 20px; -moz-border-radius-topleft: 3px; -moz-border-radius-topright: 3px; -webkit-border-top-right-radius: 5px; -webkit-border-top-left-radius: 5px;">
                                                                        <h1 style="color: #333333; font: bold 22px Arial, Helvetica, sans-serif; margin: 0; display: block !important;">
                                                                        <!-- To have a header image/logo replace the name below with your img tag -->
                                                                        <!-- Email clients will render the images when the message is read so any image -->
                                                                        <!-- must be made available on a public server, so that all recipients can load the image. -->
                                                                        <a href="http://community.jboss.org/index.jspa" style="text-decoration: none; color: #E1E1E1">Community</a></h1>
                                                                </td>

                                                        </tr>
                                                        <tr>
                                                                <td bgcolor="#FFFFFF" style="font: normal 12px Arial, Helvetica, sans-serif; color:#333333; padding: 20px;  -moz-border-radius-bottomleft: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 5px; -webkit-border-bottom-left-radius: 5px;"><h3 style="margin: 10px 0 5px; font-size: 17px; font-weight: normal;">
    start a process within another process in jbpm 4.3
</h3>
<span style="margin-bottom: 10px;">
    reply from <a href="http://community.jboss.org/people/matrixpooh">Al Nadein</a> in <i>jBPM</i> - <a href="http://community.jboss.org/message/543442#543442">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">

<div class="jive-rendered-content"><p>In short, I start a process that happily follows a few steps before it hits a 'wait' state where it's persisted to db. At some point, i have to derive by the rules if any other sub-processes have to be created. Since jbpm provides an option to create only 1 subprocess at a given step, I'm openning subprocesses programmatically, i.e. in <strong>CreateSubprocesses</strong> activity handler:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; {code}</p><p>&#160;&#160;&#160;&#160;&#160;&#160; //calculate groups to assign to a swimlane</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; taskAssignees = ...;<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; assigneeGroups.put(SharedConstants.KEY_SWIMLANE_CANDIDATE_GROUPS, taskAssignees);<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ProcessInstance processInstance = executionService.startProcessInstanceByKey("subprocess_1", assigneeGroups);&#160;&#160;&#160; </p><p>{/code}</p><p>Again, all of the above is done in an activity handler of the process that has just been instantiated and hasn't been saved to db yet.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Here's a shortened version of my jpdl:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>{code:xml}</p><p><span>&lt;process key="main" name="main" xmlns="</span><a class="jive-link-external-small" href="http://jbpm.org/4.3/jpdl" target="_blank">http://jbpm.org/4.3/jpdl</a><span>"&gt;</span><br/>&#160;&#160; <br/>&#160;&#160; &lt;start g="5,23,48,48" name="start"&gt;<br/>&#160;&#160;&#160;&#160;&#160; &lt;transition g="141,46:-88,-15" name="open.case" to="Create sub-process"/&gt;<br/>&#160;&#160; &lt;/start&gt;</p><p><br/>&#160;&#160; &lt;state g="306,193,148,52" name="Wait For Update"&gt;<br/>&#160;&#160;&#160;&#160;&#160; &lt;transition g="-23,-24" name="end" to="end1"/&gt;<br/>&#160;&#160; &lt;/state&gt;<br/>&#160;&#160; <br/>&#160;&#160; &lt;custom g="239,26,138,52" name="Create sub-process" class="<strong>CreateSubprocesses</strong>"&gt;<br/>&#160;&#160;&#160;&#160;&#160; &lt;transition g="484,52:-108,-17" name="to-split-paths" to="Wait For Update"/&gt;<br/>&#160;&#160; &lt;/custom&gt;<br/>&#160; &lt;end g="566,493,48,48" name="end1"/&gt;</p><p><br/>&lt;/process&gt;</p><p>{/code:xml} </p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>and one of possible sub-processes (simplified):</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>{code:xml}</p><p>&lt;?xml version="1.0" encoding="UTF-8"?&gt;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span>&lt;process name="test" key="test" xmlns="</span><a class="jive-link-external-small" href="http://jbpm.org/4.3/jpdl" target="_blank">http://jbpm.org/4.3/jpdl</a><span>"&gt;</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160; &lt;swimlane candidate-groups="#{assigned.responsibilities}" name="assigned-group"/&gt;<br/> <br/>&#160;&#160; &lt;start name="start1" g="16,21,48,48"&gt;<br/>&#160;&#160;&#160;&#160;&#160; &lt;transition name="to task1" to="task1" g="-17,-20"/&gt;<br/>&#160;&#160; &lt;/start&gt;<br/>&#160;&#160; <br/>&#160;&#160; &lt;end name="end1" g="219,17,48,48"/&gt;<br/>&#160;&#160; <br/>&#160;&#160; &lt;task name="task1" g="96,16,92,52" swimlane="assigned-group"&gt;<br/>&#160;&#160;&#160;&#160;&#160; &lt;transition name="to end1" to="end1" g="-20,-19"/&gt;<br/>&#160;&#160; &lt;/task&gt;<br/>&#160;&#160; <br/>&lt;/process&gt;</p><p>{/code:xml}</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p></div>

<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
    <p style="margin: 0;">Reply to this message by <a href="http://community.jboss.org/message/543442#543442">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in jBPM at <a href="http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034">Community</a></p>
</div></td>
                        </tr>
                    </tbody>
                </table>


                </td>
            </tr>
        </tbody>
    </table>

</div>

</body>
</html>