Add Workflows To Your Application On SAP Cloud Platform
Add Workflows To Your Application On SAP Cloud Platform
Exercises / Solutions
Product Management Team SAP Cloud Platform Workflow
1
CPL163
TABLE OF CONTENTS
OVERVIEW .......................................................................................................................................................3
SCENARIO DESCRIPTION ...............................................................................................................................3
WORKFLOW MODELING USING WEB IDE .....................................................................................................4
EXECUTE AND MONITOR WORKFLOW........................................................................................................26
WORKFLOW SERVICE – PUBLIC APIS .........................................................................................................38
INTERMEDIATE MESSAGE EVENTS.............................................................................................................46
DEVELOP CUSTOM SAPUI5 BASED USER INTERFACE FOR WORKFLOW ...............................................53
2
CPL163
OVERVIEW
SAP Cloud Platform Workflow service enable customers and partners to extend their core business process
executed in S/4 HANA, Ariba, Concur, SuccessFactors, C4C and other 3rd Party applications. These extension
applications enable customers to adopt changes in business very rapidly in an agile and non-disruptive way.
Workflow Service enable business users to consume SAP MyInbox, Fiori-based application to consume their
tasks. It offers out of the box Fiori-based monitoring applications to keep track of the deployed workflows and
their instances, operated in the system.
Workflow Service offers BPMN 2.0 based Business Process Modeling tools in SAP WebIDE and enable
customers and partners to quickly built and deploy workflows. It exposes REST APIs to
Read/Create/Modify/Cancel workflow instances and task instances from the system.
SCENARIO DESCRIPTION
Companies are recruiting employees using their HR application (for example: SAP SuccessFactors). A newly
recruited employee requires a smooth onboarding in order to be well integrated to the organisation and become
productive as early as possible. In SuccessFactors, the hiring manger could assign a buddy to a new hire, but
that is not sufficient to complete the onboarding. An employee requires appropriate IT equipment’s, work place
and manager may need to create travel request as part of the new job. These additional steps as part of
onboarding can be implemented using Workflow Service as an extension process to SuccessFactors
Onboarding process.
Note:
• We recommend to carefully follow the explanation section below.
• Due to the regular updates of SAP Cloud Platform Workflow, the screenshots might slightly vary from
the workflow design time on your computer.
3
CPL163
Explanation Screenshot
Username: UserXX
Password: Welcome1
4
CPL163
Explanation Screenshot
5
CPL163
Explanation Screenshot
6
CPL163
Explanation Screenshot
7
CPL163
Explanation Screenshot
Subject:
Onboarding workflow instance for user
${context.userId}
Business Key:
${context.userId}
8
CPL163
Explanation Screenshot
Destination: SFSF
Path: /empdetail/${context.userId}
9
CPL163
Explanation Screenshot
10
CPL163
Explanation Screenshot
Destination: SFSF
Path:
/directreports/${context.empData.EmpJob.managerId}
HTTP Method:
GET
Response Variable:
${context.empData.team}
27. Select the folder scripts, right click and select New-
>File.
11
CPL163
Explanation Screenshot
employee.__type__= "Employee";
employee.isFullTimeEmployee = true;
employee.countryOfCompany =
empJob.countryOfCompany;
employee.company = empJob.company;
employee.jobTitle = empJob.jobTitle;
$.context.empData.Employee = employee;
12
CPL163
Explanation Screenshot
13
CPL163
Explanation Screenshot
14
CPL163
Explanation Screenshot
Destination:
BUSINESS_RULES
Path:
/invoke?rule_service_name=DetermineEquipmentCP
L163::DetermineEquipment
HTTP Method:
POST
Request Variable:
${context.empData.Employee}
ResponseVariable:
${context.equipment.EquipmentInfo}
15
CPL163
Explanation Screenshot
var EquipmentInfo =
$.context.equipment.EquipmentInfo;
if (EquipmentInfo.length >= 0 ) {
for (var i = 0; i < EquipmentInfo.length; i++) {
var equip = EquipmentInfo[i];
equip.Status = 'New';
equip.ExpectedDate = '';
equip.RequestedLoc = 'Building 01';
EquipInfo.push(equip);
}
} else {
var equip = EquipmentInfo;
equip.Status = 'New';
equip.ExpectedDate = '';
equip.RequestedLoc = 'Building 01';
EquipInfo.push(equip);
}
$.context.equipment.EquipmentsInfo = [];
$.context.equipment.EquipmentsInfo = EquipInfo;
16
CPL163
Explanation Screenshot
17
CPL163
Explanation Screenshot
51.
18
CPL163
Explanation Screenshot
19
CPL163
Explanation Screenshot
Component URL:
ConfirmEquipment
SAPUI5 Component:
demo.sap.com.ConfirmEquipment
20
CPL163
Explanation Screenshot
Component URL:
ApproveEquipment
SAPUI5 Component:
demo.sap.com.ApproveEquipment
21
CPL163
Explanation Screenshot
22
CPL163
Explanation Screenshot
Destination:
ORDERDEST
Path:
/orderequipment
HTTP Method:
POST
Request Variable:
${context.empData.Employee}
ResponseVariable:
${context.equipment.EquipmentInfo}
23
CPL163
Explanation Screenshot
24
CPL163
Explanation Screenshot
25
CPL163
Explanation Screenshot
Username: UserXX
Password: Welcome1
26
CPL163
Explanation Screenshot
27
CPL163
Explanation Screenshot
9. Click OK button
28
CPL163
Explanation Screenshot
29
CPL163
Explanation Screenshot
1. Show Instances
To view all workflow instances created
based on the selected workflow model.
30
CPL163
Explanation Screenshot
{
"userId": "103161"
}
31
CPL163
Explanation Screenshot
32
CPL163
Explanation Screenshot
33
CPL163
Explanation Screenshot
34
CPL163
Explanation Screenshot
35
CPL163
Explanation Screenshot
36
CPL163
Explanation Screenshot
37
CPL163
SAP Cloud Platform Workflow Service provides fine granular REST APIs to access workflow and task instances
to perform various life cycle operations. These APIs are accessible through SAP API hub. All
POST/PATCH/PUT apis of workflow service are CSRF protected. So before you call these apis, you have to get
a CSRF token using the GET API.
In this section you will go through various public APIs which are essential for building a workflow application in
cloud platform. You have to use a REST client to execute these APIs. For eg: using Postman.
Explanation Screenshot
38
CPL163
Explanation Screenshot
1. Method : Get
2. REST API:
https://bpmworkflowruntimed7943e608-
d0558adbb.us2.hana.ondemand.com/work
flow-service/rest/v1/workflow-instances
3. Click Send button.
39
CPL163
Explanation Screenshot
1. Method : Get
2. REST API:
https://bpmworkflowruntimed7943e608-
d0558adbb.us2.hana.ondemand.com/wor
kflow-service/rest/v1/xsrf-token
3. Switch to Headers tab and enter a Key
Value pair.
Key: X-CSRF-Token
Value:Fetch
40
CPL163
Explanation Screenshot
1. Method: POST
2. REST API:
https://bpmworkflowruntimed7943e608-
d0558adbb.us2.hana.ondemand.com/work
flow-service/rest/v1/workflow-instances
3. Switch to Headers tab and enter a Key
Value pair.
X-CSRF-Token and set the value as the
response copied from previous step(3).
4. Content-Type: application/json.
5. Switch to Body , select the radio button
raw and enter the json payload as
"definitionId":
"employeeonboarding_XX",
"context" : {
"userId" :"103161"
}
}
Replace XX with your user number.
41
CPL163
Explanation Screenshot
1. Method : Get
2. REST API:
https://bpmworkflowruntimed7943e608-
d0558adbb.us2.hana.ondemand.com/work
flow-service/rest/v1/workflow-
instances/workflowinstanceid/context
3. Replace workflowinstanceid with
workflow instance id from the previous
step (“id” attribute of the json response).
4. Click Send button.
42
CPL163
Explanation Screenshot
1. Method : Get
2. REST API:
https://bpmworkflowruntimed7943e608-
d0558adbb.us2.hana.ondemand.com/work
flow-service/rest/v1/workflow-
instances/workflowinstanceid/execution-
logs
3. Copy and paste the workflow instance id
from the previous step (“id” attribute of the
json response.
4. Click Send button.
43
CPL163
Explanation Screenshot
44
CPL163
Explanation Screenshot
"status": "SUSPENDED"
45
CPL163
In the previous exercise, you have learnt how to model workflow by consuming services and UIs. Ordering an
equipment may not be a synchronous operation and the workflow need to wait until a confirmation received from
the procurement system. Intermediate message events enable workflow service to receive messages from an
application or remote system and correlate with workflow instances with a matching correlation condition. In the
current version ,the correlation condition is used as the business key which you have defined at the beginning of
the workflow model.
Explanation Screenshot
Username: UserXX
Password: Welcome1
46
CPL163
Explanation Screenshot
47
CPL163
Explanation Screenshot
Repeat the steps 13 - 31from section Execute and Monitor Workflow Execute and Monitor Workflow
48
CPL163
Explanation Screenshot
Key: X-CSRF-Token
Value:Fetch
49
CPL163
Explanation Screenshot
50
CPL163
Explanation Screenshot
51
CPL163
Explanation Screenshot
52
CPL163
Explanation Screenshot
Username: UserXX
Password: Welcome1
53
CPL163
Explanation Screenshot
var startupParameters =
this.getComponentData().startupParameters;
var taskModel = startupParameters.taskModel;
var taskData = taskModel.getData();
var taskId = taskData.InstanceID;
54
CPL163
Explanation Screenshot
processModel.attachRequestCompleted(func
tion() {
var
processContext = processModel.getData();
processContext.task = {};
processContext.task.Title =
taskData.TaskTitle;
processContext.task.Priority =
taskData.Priority;
processContext.task.Status =
taskData.Status;
processContext.task.CreatedOn =
taskData.CreatedOn.toDateString();
// get task
description and add it to the model
startupParameters.inboxAPI.getDescription("
NA", taskData.InstanceID).done(function(dataDescr) {
processContext.task.Description =
dataDescr.Description;
processModel.setData(processContext);
});
});
55
CPL163
Explanation Screenshot
startupParameters.inboxAPI.addAction({
action: oPositiveAction.sBtnTxt,
label: oPositiveAction.sBtnTxt,
type: "Accept"
}, oPositiveAction.onBtnPressed);
$.ajax({
url: "/bpmworkflowruntime/rest/v1/xsrf-token",
method: "GET",
headers: {
"X-CSRF-Token": "Fetch"
},
success: function(result, xhr, data) {
var token = data.getResponseHeader("X-CSRF-
Token");
var dataText = "{ \"status\":\"COMPLETED\",\"context\":
{\"workplaceConfirmed\": \"" + approvalStatus + "\" }}";
$.ajax({
url:"/bpmworkflowruntime/rest/v1/task-
instances/"+taskId,
method: "PATCH",
contentType: "application/json",
data: dataText,
headers: {
"X-CSRF-Token": token
},
success: refreshTask
});
}
});
var taskId =
this.getComponentData().startupParameters.taskModel.
getData().InstanceID;
this.getComponentData().startupParameters.inboxAPI.u
pdateTask("NA", taskId);
56
CPL163
Explanation Screenshot
57
CPL163
Explanation Screenshot
58
CPL163
Explanation Screenshot
Password: Sap@1234
59
CPL163
Explanation Screenshot
60
CPL163
Explanation Screenshot
Component URL:
AcceptWorkplace
SAPUI5 Component:
demo.sap.com.AcceptWorkplace
61
CPL163
Explanation Screenshot
62
CPL163
Explanation Screenshot
63
www.sap.com/contactsap
The information contained herein may be changed without prior notice. Some software products marketed by SAP SE and its distributors contain proprietary software components of other software vendors.
National product specifications may vary.
These materials are provided by SAP SE or an SAP affiliate company for informational purposes only, without representation or warranty of any kind, and SAP or its affiliated companies shall not be liable
for errors or omissions with respect to the materials. The only warranties for SAP or SAP affiliate company products and services are those that are set forth in the express war ranty statements
accompanying such products and services, if any. Nothing herein should be construed as constituting an additional warranty.
In particular, SAP SE or its affiliated companies have no obligation to pursue any course of business outlined in this docume nt or any related presentation, or to develop or release any functionality
mentioned therein. This document, or any related presentation, and SAP SE’s or its affiliated companies’ strategy and possible future developments, products, and/or p latform directions and functionality are
all subject to change and may be changed by SAP SE or its affiliated companies at any time for any reason without notice. The information in this document is not a commitment, promise, or legal obligation
to deliver any material, code, or functionality. All forward-looking statements are subject to various risks and uncertainties that could cause actual results to differ materially from expectations. Readers are
cautioned not to place undue reliance on these forward-looking statements, and they should not be relied upon in making purchasing decisions.
SAP and other SAP products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of SAP SE (or an SAP affiliate compan y) in Germany and other
countries. All other product and service names mentioned are the trademarks of their respective companies. See http://www.sap.com/corporate-en/legal/copyright/index.epx for additional trademark
information and notices.