Skip to Content
Author's profile photo Former Member

Easy Consumption of BPM Events via Public API – using the example of custom task notifications

Introduction

In BPM, it is already possible to send e-mail notifications to potential owners when new tasks are created. What can you do if this is not your standard notification mechanism and notifications for new tasks should be done via e.g. SMS or any push message service? Starting with BPM 7.31 SP17, a public API is available to consume process, task and message events via JMS. The task activation event for example, can be used to notify your users about a new BPM task via your notification mechanism.

How-to

The first step is to activate the publishing of BPM events to JMS. This needs to be done in SAP NetWeaver Administrator (NWA) /nwa/sys-config -> Services -> Galaxy Core Service (com.sap.glx.core.svc). For our task notification event, we set the property eventlog.publish.jms.usertask.activated to true. Now, in case of activation of a new task, a JMS message is created.

The second step is to create a consumer for these events. The easiest way is to access the BPM task activation event via message driven bean (MDB).  The consumer bean needs to extend the abstract class com.sap.bpm.jms.api.AbstractBPMMessageListener and add the following annotation:


@MessageDriven(activationConfig = {

@ActivationConfigProperty(propertyName = “destinationType”, propertyValue = “javax.jms.Topic”),

@ActivationConfigProperty(propertyName = “messageSelector”, propertyValue = SELECT_EVENT_USERTASK_ACTIVATED) }, mappedName = AbstractBPMMessageListener.JMS_TOPIC_NAME)

public class ConsumeBpmEventsBean extends AbstractBPMMessageListener{}   

To consume only task activation events, set the “messageSelector” property using the enum SELECT_EVENT_USERTASK_ACTIVATED provided by BPM public API.

The class AbstractBPMMessageListener provides different onBPM*Event methods that can be overwritten and are called each time the corresponding events are created. For a task notification, the method onBPMTaskEvent can be used. The bpmMessage contains event-specific information such as the task instance ID.

    @Override

    public void onBPMTaskEvent(final BPMTaskEventMessage bpmMessage) {

       URI taskInstanceId = bpmMessage.getTaskInstanceId();

      }

The task instance ID solely, might not be relevant for the notification mechanism, however, the task instance manager from BPM public API provides different methods to get details of the task, e.g. the potential owner, subject of the task or the task execution URL.

TaskInstanceManager taskInstanceManager = BPMFactory.getTaskInstanceManager();

TaskDetail taskDetail = taskInstanceManager.getTaskDetail(taskInstanceId);

Set<? extends IPrincipal> potentialOwners = taskDetail.getPotentialOwners();

String taskSubject = taskDetail.getSubject();

URL generateTaskExecutionUrl = taskInstanceManager.generateTaskExecutionUrl(taskInstanceId);

    

Remark on Permission

Make sure that the task details are retrieved in the context of a user who has the correct permission e.g. administrator, task administrator or potential owner. Having task details like potential owner, subject and task execution URL available, any notification mechanism can be called.

Summary

Custom implementations might require insight into the execution of business processes to either track process progress (individually and grouped) or react on changes of process or task state. BPM public API provides access to various events which occur during the life cycle when a given process or task instance reaches another state or the next step. Listening to those events enables custom applications to react accordingly.

Further Links:

BPM Documentation 7.31 SP 17

Assigned Tags

      10 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Former Member
      Former Member

      Hi Romy,

      I wonder if I use above method to catch task activated event, will the onBPMTaskEvent be triggered if a task is forwarded?

      I ask this because I want to send customize E-mail to task owner, but the Email in BPM is predefined(Even use send customized Email function, the Header and footer of Email still cannot be change).

      I can use notification before task or call EJB function in expression on activation time so the EJB function will be called when a task be activated. But both not work if a task be forwarded to another person.

      So I wonder if the public BPM api of event can solve below question.

      Thanks.

      Best regards,

      Aria

      Author's profile photo Former Member
      Former Member
      Blog Post Author

      Hello Aria,

      the use case is very interesting. We currently support only task created, task activated, task claimed, task completed and task cancelled. Please see documentation . Forwarding tasks does currently not throw an event and therefore cannot be propagated to the outer world.

      Best regards

      Romy

      Author's profile photo Former Member
      Former Member

      Hi Romy,

      Thank you for your quick reply. 🙂

      I find that notification will be send if only use standard BPM notification function. So previously I think there maybe such event .

      Maybe I can try to use task claim event instead as when a task be forwarded to someone it seems to be automatically in reserved status.

      Thanks.

      Best regards,

      Aria

      Author's profile photo Former Member
      Former Member
      Blog Post Author

      Hi Aria,

      your idea is really good. I checked it and found out that technically there is no claim event thrown when a task is forwarded.

      Best regards

      Romy

      Author's profile photo Hamdorf Tobias
      Hamdorf Tobias

      Thanks for the input. Although i would have expacted such a feature 5 years ago. It was a huge pain to send custom mails / push notifications with dirty workarounds. Nice to see that SAP is working on some weak spots 🙂 .

      Best regards,

      Tobi

      Author's profile photo Former Member
      Former Member

      If you are using SAPUI5 as a UI technology (or even WDJ) you could trigger the task claim event manually on initialization.

      So, if a forwarded task is opened by it's new receiver, it is claimed in addition and therefor this event would be available for the custom BPM Event handling.

      Best regards

      Jan

      Author's profile photo Alan Luo
      Alan Luo

      Dear  Romy Hoenig,

          this is a great new feature!

           But I have a question and you have also marked in your blog that is the Permission. when we invoke the BPM API to get process or task detail in MDB, by default the context of a user is Guest, so how can I change the Guest user to a specific user with admin action, whether this can be done by simple configuration?

          Have a nice day!

      BR,

      Alan

      Author's profile photo Former Member
      Former Member

      Hi Alan

      Check out Artjoms blog regarding this question:Impersonate user for the UME

      Author's profile photo Alan Luo
      Alan Luo

      Thank you very much Jan Nyfeler!

      Author's profile photo Kate Burcham
      Kate Burcham

      Romy,

       

      Further to one of the earlier comments,  i.e. "by default the context of a user is Guest", why does the user default to Guest?

       

      I need to know the identity of the actual logged on user. Is there any way of getting this?

       

      Regards,

       

      Kate