An embedded sub-process has certain distinct characteristics such as they always begin with a none start event and end with a non end event, they do not contain swimlanes and most importantly they share their parent's context, meaning they can access parent process data which simplifies things since you are not required to define input and output parameters and pass them as data objects. If required you can defined data objects that are local to your embedded sub-process.
An embedded sub-process is mainly used to simplify the process model by grouping activities together into an embedded sub-process that can be collapsed or expanded to hide and show the implementation details.
Another common use of the embedded sub-process is to define loops which will be the case with the sample process that we will implement as part of this blog post.
We will be implementing a very simple process which will make use of the embedded sub-process to loop through a list of order items for review.
Create the basic BPM application and BPM project (i named it OracleBPM12cEmbeddedSubProcessDemoApp and OracleBPM12cEmbeddedSubProcessDemo respectively) and choose "Empty Composite" in step 3 of the "Create BPM Application" wizard since we will first create the the XSD schema file to describe our process's input and output parameters.
Next we will create the XSD schema file where we will describe our "Order" definition that will serve as our process's input parameter. On the "Schemas" folder, right click and select "New" from the context menu and from the "New Gallery" select "XML" from the Categories" and "XML Schema" from the "Items" section.
In the "Create XML Schema" window provide a name for your schema (for example Order.xsd), a target namespace (in my example I've defined it to http://www.antonis-antoniou.blogspot.com/order) and an optional prefix (for example, ord).
Define an order element with a nested order id element and a nested list of order items where each order item has an order item id, a quantity and a price. My order element definition is as follows.
Now we are ready to define the our process. Open the composite and drag and drop a BPMN Process component onto the components section of the composite. Give your process a name, for example OrderProcess and select the "Asynchronous" message pattern.
In the second step of the "BPMN 2.0 Process" wizard, with the "Input" tab selected click on the green plus icon to add a new input argument. Give your input argument a name, for example order, and in the type click on "Browse". We need to first create a business object from the schema we've created above. So click on the "Business Object" button next to the "Find" search field to create a new business object.
We will create a business object for the order element, so give your business object a meaningful name, for example OrderBO and choose an appropriate destination module to store your business object (i create a new module called "Data"). Base your business object on your order external schema (and order element).
Click "OK" to complete the creation of the business object. You newly created business object should feature in the "Browse Types" list. Select it and click "OK". Your input argument should look as follow.
For the purpose of this demo we will not need an output argument so click "Finish" to complete the creation of your process.
Create an "Order" type process data objects to store the process input argument for reference throughout the process.
Next assign the order process input argument to the order process data objects. On the "Start Message" select "Properties", "Implementation", "Data Associations" and drag source argument (Order) to target data object (order).
Drag and drop a sub-process activity between the start and end message activities and place an interactive human task activity into the embedded sub-process. You process should look like below.
As you can see from the screenshot below I have used the count function to define the number of iterations to be equal to the number of order items defined in the request message.
Click "OK" to apply the sub-process loop definitions.
Notice how the human task activity is marked as incomplete. That’s because it hasn’t been implemented yet. So let’s create a human task definition.
Double click on the “Review Order” 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 ReviewOrderHT) and leave the rest on defaults.
Based on the above definitions, our Order process will create a human task for each order item (in parallel). To better identify each task let's personalise the human task title to include the order item id.
To simplify the assignment of tasks, open the human task definition file and in the task assignments switch from lane participants to "Names and Expressions" and define "weblogic" as the user to be assigned our order item tasks.
We are now ready to deploy and test our process (and embedded sub-process). From the EM (Enterprise Manager) invoke a new instance of your process using two order items and open on the flow trace. Your instance should have spawn two human task activities.
Go to the BPM Workspace, login as weblogic and you should see two human tasks requiring your attention.
Approve (or reject) both tasks and go back to the flow trace. You instance should have resumed execution of your main process, and because there aren't any more activities in the main flow it should have finished its execution.
Download sample application: Embedded Subprocess