Skip to Content

Applies to

The Beginners, developers, developing java/J2ee applications to consume the features available in SAP Netweaver Business Process Management 7.3 EHP1

Summary

This document details on usage BPM Java API’s to initiate a process, capturing process and task level details, nominating the task to users and Process visualization

Author: Vibha Sharma


Create on : 16-May-2013


Need to use BPM Java API’s

Important point to think about usage of BPM Java API before starting working on it is why we need to use them when we are able to work with out them. The answer to this question is very simple and straight forward, usage of API provides more control and flexibility.

Assumption:

  • User has appropriate rights to perform operation using BPM Java API’s
  • The version on netweaver is compatible
  • Process is already build and deployed on server
  • Development component where the API’s will be used should have dependency of  tc/bpem/façade/ear

Please Note: Task statistics are available only from SAP NW EHP1 SP06.In this document we will be discussing about their (BPM Java API’s) usage in

  • Initiating Process
  • Capturing process and task level details
  • Nominating the task to different users
  • Process Visualization

1. Initiating Process: Its about starting a process using Java API’s. Please find below the steps detail along with sample code

Step 1: In order to fetch the process definitions of active processes we need  ProcessDefinitionManager Interface. It can be fetched using BPMFactory

          ProcessDefinitionManager processDefinitionManager = BPMFactory.getProcessDefinitionManager();

Step 2: Next Step will be fetching the active process definition using ProcessDefinitionManager

          ProcessDefinition processDefinition = processDefinitionManager.getActiveProcessDefinition(“x.com”, “vendor~create~bpm”,           “Vendor Create Process”);

Step 3:  For getting the ProcessStartEvent via which we can actually initiate the process we need ProcessStartManager.

Hence next step is to get ProcessStartManager

          ProcessStartManager processStartManager= BPMFactory.getProcessStartManager();

Step 4: Using ProcessStartManager we can get ProcessStartEvent Set

          Set<ProcessStartEvent> processStartEventSet = processStartManager.getProcessStartEvents(processDefinition.getId());

Step 5: Creating Data Object

          ProcessStartEvent processStartEvent = processStartEventSet.iterator().next();

          DataObject dataObject = processStartManager.createDataObjectForStartEvent(processStartEvent);

Values can be set to this dataObject

Step 6: Finally initiating the process

          URI processInstanceURI = processStartManager.startProcess(processStartEvent, dataObject);

2. Capturing process and task level details

Once the process is triggered the task gets created as per process design. Via using BPM API’s we can fetch the task level details as well. Please find below steps involved along with sample code

Step1: Creating Process URI using create command

          URI processInstanceURI = URI.create(“bpm://bpm.sap.com/processs-instance/”+ String Process InstanceId);

Step2: Creating result set having the status of the task that we want to fetch

            Set<Status> taskStatus = new HashSet<Status>();     

            taskStatus.add(Status. IN_PROGRESS);

            taskStatus.add(Status.READY);

            taskStatus.add(Status.COMPLETED);

Please Note:  Suspended and Failed status are not supported

Step3: Fetching task Instance Manager Object

          TaskInstanceManager taskInstanceManager = BPMFactory.getTaskInstanceManager();

Step4: Fetching Abstract tasks using Task Instance Manager supplying the result set status  and process Instance Id as parameter

          Set<TaskAbstract> abstractTaskSet = taskInstanceManager.getTaskAbstractsByParent(processInstanceURI, taskStatus);

Step5: Looping through the taskAbstract set and fetching all the task corresponding to the process Instance URL and status supplied as parameter.

From these task, task related information can be retrieved like Task Name, Task Status, Actual Owner, Potential Owner, Start Time etc.

Context related details can also be fetched from the task using api getInputDataObject and getOutPutDataObject

3. Nominating the task to different user

Several times there comes a requirement where in we need to nominate a different user than the one actually owning the task this functionality can also be achieved via BPM Java API’s

For this we can use the task instance Id fetched in previous step and Iuser object in nominate method of taskInstanceManager

      TaskInstanceManager.nominate(URI taskInstanceId, IUser newOwner);

4. Process Visualization

Along with having task details in textual format we have option to visualize the process design and the current status of the process, in SAP BPM terminology well known as Process Visualization.

This is simplest task among all. This can be achieved using command

generateProcessInstanceVisualizationURL on  ProcessInstanceManager Object

      ProcessInstanceManager processInstanceManager ;

      processInstanceManager = BPMFactory.getProcessInstanceManager();

      processInstanceManager.generateProcessInstanceVisualizationURL(processInstanceURI));

Related Content:


http://help.sap.com/javadocs/NW73EHP1/SPS06/

http://help.sap.com/saphelp_nw73ehp1/helpdata/en/9a/eebbdf59b94c3c82af598db638b0d0/content.htm?frameset=/en/df/696c359c734820b1318e84c0f832ed/frameset.htm

Disclaimer Notice

This document may discuss sample coding or other information that does not include SAP official interfaces and therefore is not supportedby SAP. Changes made based on this information are not supported and can be overwritten during an upgrade.

SAP will not be held liable for any damages caused by using or misusing the information, code or methods suggested in this document, and anyone using these methods does so at his/her own risk.

SAP offers no guarantees and assumes no responsibility or liability of any type with respect to the content of this technical article or code sample, including any liability resulting from incompatibility between the content within this document and the materials and services offered by SAP. You agree that you will not hold, or seek to hold, SAP responsible or liable with respect to the content of this document.


To report this post you need to login first.

1 Comment

You must be Logged on to comment or reply to a post.

  1. Sung-Yen Yang

    Hi Vibha,

    Nice article, I got what I am looking for.

    One typo found in the code.

    bpm://bpm.sap.com/processs-instance/

    Apart from that, everything is perfect!

    (0) 

Leave a Reply