In this three part series we will explore an additional BPMN flow object, the subprocess. By definition, a subprocess is another type of process that can either reside within the main process or it is called by another process.
A subprocess, just like a normal process has its own start and end events and can accept data object, update data objects and return data objects. There are three types of subprocesses, “Reusable” subprocesses, “Embedded” subprocesses and “Event” subprocesses. In this first part we will dive into the “Resuable” process.
A “Resuable” processes, as the name implies is an independent process that is often used to group common and repeated flows (and activities) so that they can be reused (as opposed to re-implemented every time where needed) and which can be invoked by multiple parent processes within the same BPM project. And it’s imperative to stress here the last part, “within the same BPM project”, as a “Resuable” process cannot be used/invoked from other BPM projects. To achieve the latter you will need to use templates (feature that I will be blogging later).
As opposed to a normal process where can you use a variety of events to start and end a process (for example, message start event, timer start event, signal start event, message end event, signal end event, etc.), a “Reusable” subprocess can only start with a none start event and can only end with a none end event.
Furthermore, to invoke a “Reusable” subprocess from a main process, you will need to use a “Call” activity that by implementation allows you to call a reusable process synchronously. What this means is that when the parent process invokes a “Reusable” process it will wait until the “Reusable” child process completes execution before the parent continues its flow.
However, even though the token is passed from the parent process to the subprocess, the child subprocess does not share the parent context, meaning that the data objects of the parent process are not available to the “Reusable” child process.
Let’s see in practice how you can create a subprocess and how to invoke a subprocess from a main process. For the sake of simplicity and easiness we will build the “Quote” process depicted above but “Save Quote” service call.
Create the basic BPM application and BPM project with an asynchronous BPMN process that takes a simple string input argument (for example bidId) and returns a string argument (for example status).
Next assign the process input and output arguments to the respective process data objects. On the "Start Message" select "Properties", "Implementation", "Data Associations" and drag source argument (bidId) to target data object (pBidId). Do the same for the output argument, mapping status to pStatus.
Double click on the “Enter Quote Details” human task and from the “Properties” window go to the “Implementation” tab and click on the green “Add” button to create a new definition. Specify a name, (for example SingleOutcomeHT) and just select a single outcome, “OK”.
Let’s now create our reusable subprocess. This subprocess will just serve as a validation sub process and will include a single human task.
Right click the "BPMN Processes" folder and from the context menu select new "BPMN 2.0 Process" . Give your process a name and ensure you select "Reusable Process" from the process type selection list.
Therefore drag and drop a "Call" activity just between the two interactive human task activities. Give your "Call" activity a name (for example "Call Validate Quote Sub Process") and from the implementation tab, in the process drop down list ensure you select your reusable sub process.
Therefore using the data associations of the "Call" activity ensure that, from the input tab, you copy the pBidId main process data object to the quoteId input argument of the reusable sub process and from the output tab you copy back the outcome from the reusable sub process back to the main process.