SAP NetWeaver Business Process Management 7.3 EHP1 offers various possibilities to search process instances using process context attributes. The default out of the box solution is to use the SAP NetWeaver Administrator (NWA) and go to Operations > Processes and Tasks > Manage Processes. A process administrator/technical administrator would be able to search process instances using specific context attributes.
If you require more flexibility with respect to search criteria and provide a monitoring application outside the NWA, you can build custom monitoring application using the BPM public API. BPM Public API offers Java APIs to access process management, task management and reporting data sources.
A reporting data source is a modeled artifact in a process model and it persists the selected process context attributes for analytical/operational reporting purposes. A reporting data source persists the process instance ID together with the process context attributes, which are mapped during design time.
The context attributes persisted from a process instance can be retrieved using the BPM Reporting API. The BPM Reporting API offers various filtering capabilities to retrieve the process instances based on the filters. The life cycle of the persisted process context data is linked to the process instances. Archiving of a process instance will also archive the context attributes and it will not be accessible by using the BPM Reporting API.
The context attributes can also be persisted using custom tables. This will provide more flexibility with respect to the query filters. The context data persisted in such a custom table has its own life cycle and will not be archived as part of process archiving.
Access Process Context Attributes Using the BPM Reporting API
- Add a reporting activity in the process model and define a reporting data source.
- Add the attributes to the reporting data source.
- Map the process context attributes to the reporting data source.
Access the Reporting Data Source ID Using the BPM Public API
- Retrieve the reporting data source ID.
URI reportingDataSourceId = new URI (“bpm://bpm.sap.com/reporting-datasource/teched.sap.com/pop266~process/CustomerReq”);
The URI contains the vendor name (teched.sap.com) and the development component name (pop266~process) and the reporting data source name (CustomerReq).
- Get the reporting data source and retrieve the result set using a search parameter.
ReportingDataSource rds = BPMFactory.getReportingDataSourceManager().getReportingDataSource(reportingDataSourceId);
ReportingResultSet resultSet = BPMFactory.getReportingDataSourceManager().query(rds.getId(),”requestid”, param);
- Iterate through the result set and access the process context data and process instance ID.
Using the process instance ID retrieve the technical information about the process instance including process instance visualization URL.
String firstName = resultSet.getString(“firstname”);
String lastName = resultSet.getString(“lastname”);
String city = resultSet.getString(“city”);
String country = resultSet.getString(“country”);
URI pid = resultSet.getProcessInstanceId();
ProcessInstance processInstance = BPMFactory.getProcessInstanceManager().getProcessInstance(pid);
java.util.Date startDate = processInstance.getStartDate();
java.util.Date endDate = processInstance.getEndDate();
String subject = processInstance.getSubject();
ProcessStatus status = processInstance.getStatus();
String processurl = BPMFactory.getProcessInstanceManager().generateProcessInstanceVisualizationURL(pid).toString();
Access Process Context Attributes Using JPA
If you require little bit more flexibility with respect to the search criteria and to be independent of the process instance life cycle, you can persist the process context attributes in an application table using JPA. It is possible to access the process instance ID from the process context. The process instance ID and context attributes can be persisted using an automated activity. This provides various filtering capabilities including value range, which are possible in JPA.
- Model a table using the Dictionary perspective.
Define a Process_ID column, which represents the process instance ID.
The rest of the column represents process context attributes.
- Generate the JPA entities from the dictionary.
- Define named queries to access the table based on various filters:
- Expose a service to access the process data and persist the process data:
- Expose the above service as a Web service interface to be able to consume it in SAP NetWeaver BPM.
- Import the Web service to your BPM project in the SAP NetWeaver Developer Studio and assign the service interface to the automated activity PersistCustomerRequest.
- Define the input mapping as shown below:
- Build a Web Dynpro UI application to consume the service.
Enter a search request using the RequestID, for example, REQ*.
This will retrieve all process instances with request ID starting REQ.
Selecting a process instance will retrieve the task instances of the process instance.
The process view column navigates to the process instance graphical visualization.
REQ713 will retrieve process instances with matching context values.