How to start a process using SAP NW BPM OData Services
Hi
In my previous blog post (Working with SAP NW BPM and SAPUI5: Using SAP NW BPMs OData-Services) I wrote about SAPUI5, and how to use the new OData Services provided by SAP.
I also wrote about problems using the OData-Service for starting a new SAP NW BPM Process. This blog posts provides the solution for these problems. We investigated the issue with Andre Backofen (Andre Backofen) and it turns out the problem was our WSDL / Web Service used as Start service. It seems as a combination of anonymus complex types and naming clashes between operation and parameter caused the problem. When creating the demo I assembled the service and data type using eclipses defauld xsd / wsdl tools and haven’t checked it again as it was validated by eclipse.
However, I’d like to share the new WSDL as well as the SAPUI5 view / controller with which I was able to successfully start a Process using BPM’s OData Service.:
XSD Type:
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org/Antrag" xmlns:tns="http://www.example.org/Antrag$" elementFormDefault="qualified">
<complexType name="Antrag">
<sequence>
<element name="Mitarbeiter" type="string"></element>
<element name="Vorgesetzter" type="string"></element>
<element name="Titel" type="string"></element>
<element name="Beschreibung" type="string"></element>
<element name="Status" type="string"></element>
</sequence>
</complexType>
</schema>
WSDL:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://www.example.org/Start_Bewilligung_Async/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="Start_Bewilligung_Async" targetNamespace="http://www.example.org/Start_Bewilligung_Async/">
<wsdl:types>
<xsd:schema targetNamespace="http://www.example.org/Start_Bewilligung_Async/" xmlns:Q1="http://www.example.org/Antrag">
<xsd:import schemaLocation="Antrag.xsd" namespace="http://www.example.org/Antrag"></xsd:import>
<xsd:element name="Antrag" type="Q1:Antrag">
</xsd:element>
</xsd:schema>
</wsdl:types>
<wsdl:message name="StartBewilligungRequest">
<wsdl:part element="tns:Antrag" name="parameters"/>
</wsdl:message>
<wsdl:portType name="Start_Bewilligung_Async">
<wsdl:operation name="StartBewilligung">
<wsdl:input message="tns:StartBewilligungRequest"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="Start_Bewilligung_AsyncSOAP" type="tns:Start_Bewilligung_Async">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="StartBewilligung">
<soap:operation soapAction="http://www.example.org/Start_Bewilligung_Async/StartBewilligung"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="Start_Bewilligung_Async">
<wsdl:port binding="tns:Start_Bewilligung_AsyncSOAP" name="Start_Bewilligung_AsyncSOAP">
<soap:address location="http://www.example.org/"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
SAPUI5 view:
<core:View xmlns:core="sap.ui.core" xmlns:mvc="sap.ui.core.mvc" xmlns="sap.m" xmlns:c="sap.ui.commons"
controllerName="demo.StartAntrag" xmlns:l="sap.ui.layout" xmlns:f="sap.ui.layout.form" xmlns:html="http://www.w3.org/1999/xhtml">
<Panel id="Panel">
</Panel>
<l:Grid
defaultSpan="L12 M12 S12"
width="auto">
<l:content>
<f:SimpleForm id="Formular"
minWidth="1024"
maxContainerCols="2"
editable="true"
layout="ResponsiveGridLayout"
title="Antrag"
labelSpanL="4"
labelSpanM="4"
emptySpanL="0"
emptySpanM="0"
columnsL="2"
columnsM="2"
class="editableForm">
<f:content>
<core:Title text="Antragsdaten" />
<Label text="Titel" />
<Input id="Titel" value="{/Titel}" />
<Label text="Status" />
<Select id="Status" selectedKey="{/Status}" width="100%">
<items>
<core:Item text="" key="" />
<core:Item text="Entwurf" key="Entwurf" />
<core:Item text="Beantragt" key="Beantragt" />
<core:Item text="Bewilligt" key="Bewilligt" />
<core:Item text="Korrektur" key="Korrektur" />
<core:Item text="Abgelehnt" key="Abgelehnt" />
</items>
</Select>
<Label text="Beschreibung" />
<TextArea id="Beschreibung" value="{/Beschreibung}" rows="8" />
<core:Title text="Beteiligte" />
<Label text="Mitarbeiter" />
<Input id="Mitarbeiter" value="{/Mitarbeiter}" />
<Label text="Vorgesetzter" />
<Input id="Vorgesetzter" value="{/Vorgesetzter}" />
</f:content>
</f:SimpleForm>
</l:content>
</l:Grid>
<Bar>
<contentRight>
<Button id="Abschliessen" text="Bewilligungsprozess starten" press="handleAbschliessenPress" />
</contentRight>
</Bar>
</core:View>
SAPUI5 controller:
jQuery.sap.require("demo.Util");
jQuery.sap.require("sap.m.MessageBox");
sap.ui.controller("demo.StartAntrag", {
getFormFragment : function() {
return sap.ui.xmlfragment("demo.Antrag", this);
},
/**
* Called when a controller is instantiated and its View
* controls (if available) are already created. Can be used
* to modify the View before it is displayed, to bind event
* handlers and do other one-time initialization.
*
* @memberOf demo.Antrag
*/
onInit : function() {
var oPanel = this.getView().byId("Panel");
this.antragModel = new sap.ui.model.json.JSONModel();
this.getView().setModel(this.antragModel);
var oMitarbeiter = this.getView().byId("Mitarbeiter");
oMitarbeiter.setValue("Nyfeler Jan");
oMitarbeiter.setEnabled(false);
var oVorgesetzter = this.getView().byId("Vorgesetzter");
oVorgesetzter.setValue("Nyfeler Jan");
oVorgesetzter.setEnabled(false);
var oStatus = this.getView().byId("Status");
oStatus.setSelectedKey("Entwurf");
oStatus.setEnabled(false);
},
handleAbschliessenPress : function() {
var that = this;
var startProcessSvcURL = "/bpmodata/startprocess.svc/novobc.ch/pr~pm~demo/Bewilligung";
var oModel = new sap.ui.model.odata.ODataModel(startProcessSvcURL, true);
var startData = {};
startData.ProcessStartEvent = {};
startData.ProcessStartEvent.Antrag = this.antragModel.getProperty("/");
oModel.create("/StartData", startData, null, function(oData, oResponse) {
sap.m.MessageBox.show("Der Prozess wurde erfolgreich gestartet. Sie können das Fenster schliessen.", sap.m.MessageBox.Icon.SUCCESS, "Prozess erfolgreich gestartet");
}, function(oEvent) {
sap.m.MessageBox.show("Fehler beim Prozessstart.", sap.m.MessageBox.Icon.ERROR, "Fehler beim Prozessstart");
});
}
});
I’d like to thank Andre Backofen (Andre Backofen) as well as my colleagues Patrick Wenger (Patrick Wenger) and Werner Schwarz (Werner Schwarz) for their support.
Cheerio
Jan
Edit:
I’d like to mention that you have to use not the data object as mentioned in the official documentation BPM OData Service for Starting BPM Processes – Modeling Processes with Process Composer – SAP Library for starting a process but the used data type name instead
In example I provided, data object name as well as data type name were the same so it worked…..
Hi Jan,
Very nice blog, and well explained. Every Minute details are covered and the code spinster are a added bonus.
Cheers
Piyas
Hi Jan
Awesome, this was exactly, what i was looking for.
Keep up the good work.
Best regards
Maurice
Hi Jan,
Is it possible to trigger the BPM process from SAP UI5 application.
For example : When User submits a request in UI5 application, it should trigger the bpm process. In this case, how the integration works.
My Flow is like BPM(1st Process) -> UI5 ---> BPM(2nd Process)
Please share some examples.
Regards
Karthik S
Hi Karthik
I'm not sure if I understand your question correctly. But in general, of course you can start a bpm process or trigger an intermediate message event from sapui5.
If you want to achieve this in a certain sequence, you can nest odata-model success handlers or use jquery deferred/promise.
Regarding what odata services exist, please visit https://blogs.sap.com/2013/10/18/bpm-odata-exploring-the-service/
Hi Jan Nyfeler,
I am getting error when I try to post the data in /StartData. My post action fails. I don't know the root cause of the error. I followed the steps which you have given in the blog.
Error Message :
2017-05-11 : The following problem occurred: HTTP request failed500,Internal Server Error,{"error":{"code":"INVALID_DATA","message":{"lang":"en","value":"An error occurred. 500 Internal Server Error. Log ID: C000A2352055475F0000000001120078"}}} -
My XSD structure :
<xsd:complexType name="Form">
<xsd:sequence>
<xsd:element maxOccurs="1" minOccurs="1" name="Name"
type="xsd:string" />
<xsd:element maxOccurs="1" minOccurs="1" name="Age"
type="xsd:string" />
<xsd:element maxOccurs="1" minOccurs="1" name="Country"
type="xsd:string" />
</xsd:sequence></xsd:complexType></xsd:schema>
UI5 Submit Button Action:
var startProcessSvcURL =
"https://host:port/bpmodata/startproces.svc/demo.sap.com/initialbpmproject2/usergenBPMProcess";
this.processStartODataModel = new sap.ui.model.odata.ODataModel(startProcessSvcURL, true);
var startData = {};
startData.ProcessStartEvent = {};
var jsonModel = this.getView().getModel();
startData.ProcessStartEvent.Form = [{Name : "karthik", Age :"26", Country :"India"}];
this.processStartODataModel.create("/StartData", startData,null,
function sendData_OnSuccess(oData, response) {
alert("Task has been completed successfully");
},
function sendData_OnError(oError) {
alert("Task could not be completed");
});
Regards
Karthik S