If you haven’t done the steps described in the Build it yourself
section, import the *.twx file named ‘BPMN20_Samples -
LaptopOrder_-_ad-hoc_adv_COMPL.twx’ into
Remember from the last section that we have implemented two options
exploiting the ad-hoc event:
Executing the sample will be done in IBM Process Portal, therefore open
it using the Process Portal link made available after having installed IBM
Business Process Manager.

Logon with ‘tw_admin’ and ‘tw-admin’.

After the login, your inbox is opened, and could be empty or not,
depending if you have running process instances and / tasks assigned to you or
not.

Let’s begin to
run the sample exploring option 1.
Click the ‘New’
button, and create an instance of the process named ‘LaptopOrder_EditAndFile’.

A new process instance is created, and the process engine navigates to
the first task named ‘Edit Laptop Order’. Click on the Run button on the right
hand side to run the task.

You can accept the default fields, but enter an Order ID and remember
the Order ID. When finished, click on ‘Order now!’

Now open the process instance view by clicking on the process instance
name.

Look at the data, then open the process diagram by clicking on the icon
available in the icon list.

The process instance is waiting for the completion of the task ‘Validate
Laptop Order’.

Close the process diagram, run the ‘Validate Laptop Order’ task by
clicking on the ‘Run’ button. Look at the task implementation and select ‘Order
Approved’. When done, click OK.

When done, no task is ready for execution, because the process instance
is waiting at the event gateway. Now click on ‘Actions’ and select the action
named ‘ad-hoc actions – Cancel laptop order’.

Now, open the process instance diagram again.

You can see that the send cancel event was sent and received by the
event gateway, and the process instance moved on to the ‘Cancel Order’ task.
Run the ‘Cancel Order’ task to complete the process instance.

Repeat the steps explained here for option 1, and select ‘ad-hoc
actions -Modify Laptop Order’ BEFORE
having validated the laptop order. Now, when the ‘Validate Laptop Order’ task
is done, as the modify event was triggered already, the process engine
immediately navigates to the ‘Edit Laptop Order’ task, because the modify order
receive event has the ‘Durable Subscription’ attribute switched on. (Durable Subscription :
Enable the Durable
Subscription check box to allow the message
event to receive an incoming message, even when the message event is not in an
active state.)
This works as well for the action named ‘ad-hoc actions – Cancel Laptop Order’
– but will have different consequences for the process instance execution for
sure. Try it out, by creating a new process instance for ‘LaptopOrder_EditAndFile’.
The important
aspect is that option 1 requires the ‘Validate Laptop
Order’ task to be executed BEFORE the cancel or modify event is consumed.
If the cancel or modify event is triggered before the ‘Validate Laptop Order’
is done, the procurement manager has to perform the order validation even if
this is no longer required.
In comparison to
the BPMN20 – All events sample, or the BPMN20 – Event gateway sample (both
published here on the Samples page), the events expected at the event gateway
are not triggered from outside the process, but directly here from within the
process using the ad-hoc events.
Now, let’s have
a look at option 2.
This option 2
will interrupt the running process instance if the user performs either the
cancellation or modification action.
First, we need
to create a new process instance. Click the ‘New’ button, and create an
instance of the process named ‘Int_LaptopOrder_EditAndFile’.

A new process instance is created, and the process engine navigates to
the first task named ‘Edit Laptop Order’. Click on the Run button on the right
hand side to run the task.
On the task implementation, you can accept the default fields, but enter
an Order ID and remember the Order ID. When finished, click on ‘Order now!’

Now open the process instance view by clicking on the process instance
name. Look at the data, then open the process diagram by clicking on the icon
available in the icon list.

The process diagram shows that the task named ‘Validate Laptop Order’
and the event sub process are ready for execution. Now, close the process
diagram again, and select the action named ‘ad-hoc actions – Cancel laptop
order’.

Immediately, the process moves on to the ‘Ad-hoc Cancel Order’ task as
indicated in the process instance view.

Now let’s explore the process instance diagram again. Open the process
diagram again.

Click on the active event subprocess to see what’s going on in there:

As indicated on the process instance view window, the ad-hoc Cancel
Order task is ready for execution. Remember that we have set one of the process
variables to indicate whether the user is asking for the cancellation, or for
the modification. This variable is evaluated at runtime in the gateway, and
either the cancellation path is followed, or the modification path is followed.
Repeat this option, but this time select to modify the order.
So the difference between option 1 and option 2 is that because if the
interruption of the process instance in option 2, the procurement manager no
longer has to validate an order that was already cancelled, or did experience a
request for modification.
This completes the run the sample section.