0% found this document useful (0 votes)
198 views

Add Workflows To Your Application On SAP Cloud Platform

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
198 views

Add Workflows To Your Application On SAP Cloud Platform

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 64

CPL163

Add Workflows to Your Application on SAP Cloud


Platform
CPL163

Exercises / Solutions
Product Management Team SAP Cloud Platform Workflow

Krasimir Kondarev SAP SE

Tobias Breyer SAP SE

Venugopal Chembrakalathil SAP SE

Songa Venkatrami Reddy SAP Labs India(P) Ltd

Milton Reuben Rodrigues SAP Labs India(P) Ltd

Seshadri R Sreenivas SAP Labs India(P) Ltd

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

WORKFLOW MODELING USING WEB IDE

Explanation Screenshot

1. Open Chrome or Firefox browser


2. Copy and Paste the below URL to your browser.
https://webidecp-
d0558adbb.dispatcher.us2.hana.ondemand.com/

3. Log on to WebIDE using the following credentials:

Username: UserXX
Password: Welcome1

Your session trainer will allocate you a number


and use this to replace XX from the user
number.

4. Click on menu option Tools and select


Preferences

4
CPL163

Explanation Screenshot

5. From the left-tab options, select Features


6. In the Features page, filter the features using the
search text “Workflow”.

7. If the Workflow Editor status is OFF, click the


toggle button to enable the feature

If the Workflow Editor is status is already ON,


proceed with step 10.

8. Save the changes by clicking the Save button.

Note: This will enable the Workflow Editor feature in


WebIDE

9. Click Refresh button to refresh WebIDE.

Note: This will restart the WebIDE.

5
CPL163

Explanation Screenshot

10. From the options in the extreme left-bar,


select </> to open the workspace in
development perspective mode.

Info: If your workspace is not empty, please


delete the projects by right click and delete
from workspace.

11. Select Workspace and right-click and select option


New Project from Template.

12. Select Category as Business Process


Management from the drop down and click Next.

6
CPL163

Explanation Screenshot

13. Enter project name as SAPCPWorkflow and click


on the Next Button.

14. Enter the Workflow Name as


EmployeeOnboarding_XX.

Note: Make sure you replace the XX from


workflow name with your user number provided by
your trainer.

15. Click on Next button

7
CPL163

Explanation Screenshot

16. Click Finish button to complete the Project


creation.

17. In the Workflow Properties, enter the following data:

Subject:
Onboarding workflow instance for user
${context.userId}

Business Key:
${context.userId}

Note: ${context.userId} represents the workflow


context attribute and used as a Business Key to
uniquely identify the workflow instance.

18. Select the StartEvent1, and click on Task speed


button and then select the button with option Service
Task

Note: Task speed button will have this icon:

Note: Due to continuous development changes in the


cloud platform, the speed button options might not
appear in the same order as shown in the screenshot

8
CPL163

Explanation Screenshot

A new service task will be added to the workflow.

Note: Service task is used to call rest or OData


service to get or post data.

19. Select the ServiceTask1


20. In the Service Task Properties, enter the
Name: GetEmployeeDetails

21. Switch to DETAILS tab and enter the following:

Destination: SFSF

Path: /empdetail/${context.userId}

HTTP Method: GET

Response Variable: ${context.empData}

Note: SFSF is a service end point destination


defined in the SAP Cloud Platform Cockpit under
Destinations

9
CPL163

Explanation Screenshot

22. Select GetEmployeeDetails service task and click


the Gateway speed button and then select the
Parallel Gateway speed button

Note: Due to continuous development changes in


the cloud platform, the speed button options might
not appear in the same order as shown in the
screenshot

Note: Gateway speed button will have this icon:

A Parallel Gateway will be added to the workflow.

Note: A Parallel Gateway enable workflow service


to execute workflow in parallel.

23. Select the ParallelGateway1, click Task speed button


and then select Service Task speed button.

A new service task will be added to the workflow.

10
CPL163

Explanation Screenshot

24. Select the newly added service task


25. In the Service Task Properties, enter the
Name: GetBuddyList

26. Switch to DETAILS tab and enter the following:

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

28. Enter the File Name as PrepareRulesInput.js

29. Copy and paste the below script in the editor:

var employee = {};


var empJob = $.context.empData.EmpJob;

employee.__type__= "Employee";
employee.isFullTimeEmployee = true;
employee.countryOfCompany =
empJob.countryOfCompany;
employee.company = empJob.company;
employee.jobTitle = empJob.jobTitle;

$.context.empData.Employee = employee;

30. Click Save button.

31. Switch to tab EmployeeOnboardingXX.workflow.

12
CPL163

Explanation Screenshot

32. From the palette on left-side of the workflow editor,


click on the Task option and then select the Script
Task option

Note: The Task option with have this icon

Note: If you do not see the Task option, then use


the scroll option to scroll-down to the palette options

33. Select the ParallelGateway1 and click on the


Sequence Flow speed button and then drag-and-
drop the connection to the new script task

Note: Due to continuous development changes in the


cloud platform, the speed button options might not
appear in the same order as shown in the screenshot

Note: Sequence Flow will have this icon

34. Select the ScriptTask1

35. In the Script Task Properties, enter the following:


Name: PrepareRulesInput

36. Click on Browse button.

13
CPL163

Explanation Screenshot

37. Expand SAPCPWorkflow->Scripts folder and select


PrepareRulesInput.js file.
38. Click OK button.

39. Select the ‘PrepareRulesInput’ script task and click


on the Task speed button and then select Service
Task speed button

Note: Task speed button will have this icon:

Note: Due to continuous development changes in the


cloud platform, the speed button options might not
appear in the same order as shown in the screenshot

40. Select the newly added service task


For example: ServiceTask5 as seen in screenshot

41. In the Service Task Properties, enter the following:


Name: DetermineEquipment

14
CPL163

Explanation Screenshot

42. Switch to DETAILS tab, and enter the following:

Destination:
BUSINESS_RULES

Path:
/invoke?rule_service_name=DetermineEquipmentCP
L163::DetermineEquipment

HTTP Method:
POST

Path to XSRF Token:


/xsrf-token

Request Variable:
${context.empData.Employee}

ResponseVariable:
${context.equipment.EquipmentInfo}

Note: This service task would invoke the business


rules service that is modeled and deployed in the
SAP Cloud Platform. The path is the rest-based
endpoint for the business rules service

43. Below the project SAPCPWorkflow, select scripts


right click and select New->File.

15
CPL163

Explanation Screenshot

44. Enter the File Name as UpdateContext.js

45. Copy and paste the below script:

var EquipmentInfo =
$.context.equipment.EquipmentInfo;

var EquipInfo = [];

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

46. Click Save button.

47. Switch tab to EmployeeOnboardingXX.workflow

48. Select script task with name DetermineEquipment


and click on the Task speed button and then select
Script Task speed button

Note: Task speed button will have this icon:

Note: Due to continuous development changes in the


cloud platform, the speed button options might not
appear in the same order as shown in the screenshot

49. In the Script Task Properties, enter the following:


Name: UpdateContext

50. Click on Open Browse Button

17
CPL163

Explanation Screenshot

51.

52. Select the GetBuddiesList service task, click on the


Gateway speed button and then select Parallel
Gateway speed button

Note: Gateway speed button will have this icon:

Note: Due to continuous development changes in the


cloud platform, the speed button options might not
appear in the same order as shown in the screenshot

53. Select the Update Context script task, click on the


Sequence Flow speed button and then drag-and-
drop the connection to Parallel Gateway as shown

Note: Due to continuous development changes in


the cloud platform, the speed button options might
not appear in the same order as shown in the
screenshot

Note: Sequence Flow will have this icon

18
CPL163

Explanation Screenshot

54. Select the ParallelGateway2, click on the Task


speed button and select User Task speed button
as shown

Note: Task speed button will have this icon:

Note: Due to continuous development changes in


the cloud platform, the speed button options might
not appear in the same order as shown in the
screenshot

55. Select the newly added user task


For Example: UserTask1 as seen in the screenshot

56. In the User Task Properties, enter the following:


Name: Confirm or Change Equipment

57. Switch to DISPLAY TEXTS tab


58. Enter Subject as
Confirm or Change Equipment for
${context.empData.User.firstName}
${context.empData.User.lastName}

59. Switch to RECIEPENTS tab


60. In Users, enter your logon User ID(UserXX).

Note: It is possible to add multiple users (comma


separated) or user group

19
CPL163

Explanation Screenshot

61. Switch to USER INTERFACE tab.


62. Enter the following:

HTML5 App Name:


onboardinguiapp

Component URL:
ConfirmEquipment

SAPUI5 Component:
demo.sap.com.ConfirmEquipment

Note: There is an SAPUI5 application


(onboardinguiapp) which is modeled and deployed in
SAP Cloud Platform.

63. Select the Confirm or Change Equipment user task


64. Click on the Task speed button and then select User
Task speed button

Note: Task speed button will have this icon:

Note: Due to continuous development changes in


the cloud platform, the speed button options might
not appear in the same order as shown in the
screenshot

20
CPL163

Explanation Screenshot

65. In the User Task Properties, enter the following:


Name: Approve Equipment

66. Switch to DISPLAY TEXTS tab and enter Subject as


Approve Equipment for
${context.empData.User.firstName}
${context.empData.User.lastName}

67. Switch to RECIEPENTS tab


68. In Users, enter your logon User ID(UserXX).

Note: It is possible to add multiple users (coma


separated) or user group

69. Switch to USER INTERFACE tab


70. Enter the following:

HTML5 App Name:


onboardinguiapp

Component URL:
ApproveEquipment

SAPUI5 Component:
demo.sap.com.ApproveEquipment

21
CPL163

Explanation Screenshot

71. Select the Approve Equipment user task


72. Click on the Gateway speed button and then select
Exclusive Gateway speed button

73. In the Exclusive Gateway Properties, enter the


Name: Equipment Approved?

74. Select the Equipments Approved? gateway


75. Click on the Task speed button and then select
Service Task speed button

Note: Task speed button will have this icon:

Note: Due to continuous development changes in


the cloud platform, the speed button options might
not appear in the same order as shown in the
screenshot

22
CPL163

Explanation Screenshot

76. Select the newly added service task


For Example: ServiceTask6 as seen in the
screenshot

77. In the GENERAL tab, enter the following


Name: OrderEquipment

78. Switch to DETAILS tab and enter the following:

Destination:
ORDERDEST

Path:
/orderequipment

HTTP Method:
POST

Request Variable:
${context.empData.Employee}

ResponseVariable:
${context.equipment.EquipmentInfo}

79. Select EquipmentApproved? gateway

80. Click on the Sequence Flow speed button and then


drag-and-drop the connection to Confirm or Change
Equipment user task

Note: Due to continuous development changes in the


cloud platform, the speed button options might not
appear in the same order as shown in the screenshot

23
CPL163

Explanation Screenshot

81. Select the newly added sequence flow above and


enter the following:

Name: Reject or Rework


Condition: ${context.equipApproved==false}

82. Select the sequence flow connecting


EquipmentApproved? gateway and OrderEquipments
service task and enter the Name as Approved

83. Select the Default check box.

Note: You will see a slight change in the connection


as soon as you select default. This means that if
none of the gateway conditions are satisfied then the
workflow will take this route.

24
CPL163

Explanation Screenshot

84. Save the workflow model by clicking the Save button


on the top-left corner of the editor as shown.

85. Select the workflow model and right-click.


86. Select Deploy  Deploy to SAP Cloud Platform
Workflow.

Note: The Workflow model will be deployed and is


ready to be executed.

Note: If there are any validation errors, then the


deployment will fail and you will see the errors on top
right corner of the editor under notifications icon.

25
CPL163

EXECUTE AND MONITOR WORKFLOW

Explanation Screenshot

1. Open Chrome or Firefox browser


2. Copy and Paste the URL to your browser
https://flpnwc-
d0558adbb.dispatcher.us2.hana.ondeman
d.com/sites#Shell-home

3. Logon to the My Inbox with credentials:

Username: UserXX
Password: Welcome1

This will open the Fiori Launchpad.

After log on, check if you see My Inbox,


Workflow Definitions and Workflow Instances
tiles. If Yes, proceed with Step 13.

4. Click on the User icon

26
CPL163

Explanation Screenshot

5. Click on App Finder

Note: It will open a new interface to select


different applications which are available in the
system.

6. Select Workflow option

27
CPL163

Explanation Screenshot

7. Select My Inbox tile and click on the pin

8. Check My Home option

9. Click OK button

10. Do the same for Monitor Workflow 


Workflow Definitions

28
CPL163

Explanation Screenshot

11. Do the same for Monitor Workflow 


Workflow Instances

12. Click Home button to navigate to the Fiori


Launchpad.

29
CPL163

Explanation Screenshot

13. Select Monitor Workflows Workflow


Definitions tile.

14. Filter the workflow definitions using the last two


digits of your user-id which you have used while
modeling the workflow model.
For Example: _00.

There are three actions on the footer.

1. Show Instances
To view all workflow instances created
based on the selected workflow model.

2. Start New Instance


To create a new workflow instance.

3. Download Workflow Model


To download the last deployed version of
workflow model.

15. Click Start New Instance.

Note: It will open a new popup window to enter an


input payload to start a workflow instance.

30
CPL163

Explanation Screenshot

16. In the popup, enter the JSON payload as

{
"userId": "103161"
}

17. Click Start New Instance button

You could see the message toast if the workflow


instance has successfully created.

18. Click Show Instances button to see the newly


created workflow instances.

31
CPL163

Explanation Screenshot

19. You could see the newly created workflow


instance with status Running

Note the following tabs:


1. EXECUTION LOG – which shows what are
all the steps executed until now. The last
step indicates there is a user task ‘Confirm
or Change Equipment for Ervin Clarke’. The
recipient should be your user id so that you
could claim and complete the user task.

2. ERROR MESSAGES – which shows if there


are any errors while executing the workflow
instance.

3. WORKFLOW INFORMATION – which is the


table that provides technical information
about the workflow instance such as
instance id, workflow definition id, version,
started by, started at and Business Key
modeled by you in design time.

20. Click the Home button.

32
CPL163

Explanation Screenshot

You could see the My Inbox tile indicating 1 Task


available to the user.

21. Click on the tile and you will be navigated to My


Inbox application.

Note: SAP My Inbox offers simple text search,


various sorting, filtering and grouping capabilities.
You could see these actions on the left side of the
footer.

On the right side of the footer you could see


actions like Confirm, Show Log and Claim where:

Confirm is a custom action modeled to complete


the task.

Show Log enable the business user to see the


previous steps of the workflow instance provided
it is enabled in the design time.

Claim enable business user to own the task so


that no other business user would be able to work
on the same user task instance. A business user
could release a claimed task by using the
Release action so that the same user task
instance will be visible to other business users
who are assigned as the task owners.

33
CPL163

Explanation Screenshot

22. Click on Claim button.

A successful claim is shown as message toast


and that will enable the Release button.

The listed equipment is determined using the


business rules executed in the workflow model.

23. Click on the + button to add an additional


equipment for the new hire.

24. Choose Smartphone as Type and click Save


button.

34
CPL163

Explanation Screenshot

25. Click Confirm button to complete the task.

26. The task Item list will be empty


27. Click on REFRESH to see the new list of available
tasks

You will see a new task with name ‘Approve


Equipment for Ervin Clark’

35
CPL163

Explanation Screenshot

28. Select the task with name ‘Approve Equipment for


Ervin Clark’ to open the task user interface

29. Click Approve button

Note: If you choose Reject, a new user task of


type Confirm or Change Equipment will be
available in the task list.

Note: If you have approved the user task above, then


the workflow instance will be completed

Note: My Inbox will be empty now.

30. Click the Home button to navigate to the Fiori


Launchpad.

36
CPL163

Explanation Screenshot

31. Select Monitor Workflows  Workflow


Definitions and filter the definitions using your
workflow definition id (For Example: _00),

32. Click on Show Instances button to check the


instance.

As the workflow is completed, there will not be


any workflow instance in running state.

37
CPL163

WORKFLOW SERVICE – PUBLIC APIS

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

1. Open Postman or any similar REST client and


enter the following
API : Get All Workflow Definitions
1. Method : Get
2. Authorization Type: Basic Auth
3. REST API:
https://bpmworkflowruntimed7943e608-
d0558adbb.us2.hana.ondemand.com/work
flow-service/rest/v1/workflow-definitions
4. UserName: wfapiuser
5. Password:Welcome1
5, Click Update Request and Send.button

Response: All deployed workflow definitions are


retrieved from the tenant.

38
CPL163

Explanation Screenshot

2. API : Get All Workflow Instances

1. Method : Get
2. REST API:
https://bpmworkflowruntimed7943e608-
d0558adbb.us2.hana.ondemand.com/work
flow-service/rest/v1/workflow-instances
3. Click Send button.

Response: All Running workflow instances

39
CPL163

Explanation Screenshot

3. API: Get CSRF token

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

4. Click Send button

40
CPL163

Explanation Screenshot

5. If the REST api call is successful with Status 200,


Swtich to Headers and Copy the value of attribute
x-csrf-token

4. API: Create workflow Instance

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

6. Click Send button.


A successful API call would create a new
workflow instance and the json response
provide technical information about the
workflow instance.

Copy the “id” attribute from Response to


use in the next API. Keep this in a notepad
as workflow instance id and it will be used
in next steps.

5. API : Get Context of a workflow Instance

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

6. API: Get workflow logs of a workflow instance

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.

7. API:Get user task instances of a workflow


instance.
1. Method : Get
2. REST API:
https://bpmworkflowruntimed7943e608-
d0558adbb.us2.hana.ondemand.com/work
flow-service/rest/v1/task-
instances?workflowInstanceId=id
3. Replace the request parameter “id” with
workflow instance id. Copy and paste the
workflow instance id from the step 4 (“id”
attribute of the json response.
4. Click Send button.

Copy the “id” attribute from response payload and


keep it in a notepad as task instance id. It will be used
in the next steps.

43
CPL163

Explanation Screenshot

8. API:Get details of a user task instance.


1. Method : Get
2. REST API:
https://bpmworkflowruntimed7943e608-
d0558adbb.us2.hana.ondemand.com/work
flow-service/rest/v1/task-
instances/taskinstanceid

3. Replace taskinstanceid by Copy and


paste the task instance id from the
previous step (“id” attribute of the json
response)
4. Click Send button.

9. API:Get workflow context using user task


instance.
1. Method : Get
2. REST API:
https://bpmworkflowruntimed7943e608-
d0558adbb.us2.hana.ondemand.com/work
flow-service/rest/v1/task-
instances/taskinstanceid/context

3. Copy and paste the task instance id from


the previous step (“id” attribute of the json
response)
4. Click Send button.

44
CPL163

Explanation Screenshot

10. API:Suspend/Resume a workflow instance.


Get a XSRF token by using Step 3.
1. Method : PATCH
2. REST API:
https://bpmworkflowruntimed7943e608-
d0558adbb.us2.hana.ondemand.com/work
flow-service/rest/v1/workflow-
instances/workflowinstanceid

3. Copy and paste the workflow instance id


from step 6 (“id” attribute of the json
response)
4. 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).
5. Content-Type : application/json.
6. Switch to Body, select radio button raw
and enter the json payload as

"status": "SUSPENDED"

7. Click Send Button

You could navigate to FIORI launch pad


https://flpnwc-
d0558adbb.dispatcher.us2.hana.ondemand.com/sites
#Shell-home and click Monitor Workflows -
Workflow Instances and check the status of your
workflow instance.

The Workflow Execution log indicates the user


Suspended the workflow instance.

Repeat Step 9 and replace the body as


{
"status": "RUNNING"
}
This will resume the workflow instance.

45
CPL163

INTERMEDIATE MESSAGE EVENTS

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

1. Open Chrome or Firefox browser


2. Copy and paste below URL in your browser:
https://webidecp-
d0558adbb.dispatcher.us2.hana.ondemand.com/

Log on to WebIDE using the following credentials:

Username: UserXX
Password: Welcome1

Your session trainer will allocate you a


number and use this to replace XX from the
user number.

3. From the project, open the workflow model with


name: EmployeeOnboarding_XX where XX is
your user number

46
CPL163

Explanation Screenshot

4. Select the OrderEquipments service task

5. Click on the Events speed button and select


Intermediate Message Event speed button

Note: Intermediate Message Event speed button


will have this icon:

Note: Due to continuous development changes in


the cloud platform, the speed button options might
not appear in the same order as shown in the
screenshot

6. Select the Intermediate Message Event and Enter


Name as ConfirmOrder

7.Switch to Details tab and Enter the following

Message Name: ConfirmOrder_XX

Response Variable: ${context.OrderConfirmation}

47
CPL163

Explanation Screenshot

Note: Replace _XX with your user number. The


message correlation during runtime using the
following attributes to identify the message event.
1. Workflow Definition ID
2. Message Name
3. BusinessKey
The Response Variable contains the context payload
received by the message event.

The message payload structure for Example:


{
"businessKey": "103161",
"definitionId": "ConfirmOrder_00",
"workflowDefinitionId":
"employeeonboarding_00",
"context":{"OrderConfirmaton":"ord1234"}
}

8. Select the workflow model and right-click.


9. Select Deploy  Deploy to SAP Cloud Platform
Workflow.

Note: The Workflow model will be deployed and is


ready to be executed.

Note: If there are any validation errors, then the


deployment will fail and you will see the errors on
top right corner of the editor under notifications
icon.

Repeat the steps 13 - 31from section Execute and Monitor Workflow Execute and Monitor Workflow

48
CPL163

Explanation Screenshot

10. Click on Show Instances button to check the


instance.

As the workflow is in Running state, the workflow log


indicates it is waiting at a message event.

11. Open Postman or any similar REST client and


enter the following
12. Method : Get
13. REST API:
https://bpmworkflowruntimed7943e608-
d0558adbb.us2.hana.ondemand.com/workflow-
service/rest/v1/xsrf-token
14. UserName: wfapiuser
15. Password:Welcome1

Note: All workflow service POST/PUT/PATCH REST


APIs are CSRF protected. So we require to get a
CSRF token before calling the REST API to send a
message to the workflow instance.

16. Switch to Headers tab and enter a Key Value pair.

Key: X-CSRF-Token

Value:Fetch

49
CPL163

Explanation Screenshot

17. Click Update Request


18. Click Send

19. If the REST api call is successful with


Status 200, Swtich to Headers
20. Copy the value of attribute x-csrf-token

21. Change the following in REST client


1. Method: POST
2. REST API:
https://bpmworkflowruntimed7943e608-
d0558adbb.us2.hana.ondemand.com/workflow-
service/rest/v1/messages
22. Switch to Headers and add a key X-CSRF-
Token and enter the value as you copied from
the previous step.

50
CPL163

Explanation Screenshot

23. Switch to Body and select raw and


JSON(application/json)
24. Copy the below json payload
{
{
"businessKey": "103161",
"definitionId": "ConfirmOrder_XX",
"workflowDefinitionId": "employeeonboarding_XX",
"context":{"OrderId":"ord1234"}
}

Replace XX with your User number.


}

25. Click Send button. The response shows the


instances consumed the message which you
sent.

51
CPL163

Explanation Screenshot

26. Select Monitor Workflows  Workflow


Definitions and filter the definitions using
your workflow definition id (For Example:
_00),

27. Click on Show Instances button to check


the instance.

28. As the workflow is completed, there will


not be any workflow instance in running
state.

52
CPL163

DEVELOP CUSTOM SAPUI5 BASED USER INTERFACE FOR WORKFLOW

Explanation Screenshot

6. Open Chrome or Firefox browser


7. Copy and paste below URL in your browser:
https://webidecp-
d0558adbb.dispatcher.us2.hana.ondemand.com/

Log on to WebIDE using the following credentials:

Username: UserXX
Password: Welcome1

Your session trainer will allocate you a


number and use this to replace XX from the
user number.

8. Right click on Workspace and choose Import-


>Application from SAP Cloud Platform.

9. In the Import popup, Filter the application name


employeeonboardinguitemplate
10. Select the employeeonboardinguitemplate
application
11. Enter Target Folder as SAPCPUI

12. Click OK button

53
CPL163

Explanation Screenshot

The AcceptWorkplace task interface is imported


under the workflow project

13. Click on Component.js file under your project in:


SAPCPWorkflow/AcceptWorkplace

Note: Component.js file enables an application


developer to call workflow service REST APIs and
get workflow context and bind the context to the
component or view.

14. Copy the below code snippet under the section:


//1. get task instance data.

var startupParameters =
this.getComponentData().startupParameters;
var taskModel = startupParameters.taskModel;
var taskData = taskModel.getData();
var taskId = taskData.InstanceID;

Note: The startup parameter provides access to


the task instance id.

15. Copy the below code snippet under the section:


//2. Get process context using task instance id

var processModel = new


sap.ui.model.json.JSONModel("/bpmworkflowruntime/re
st/v1/task-instances/"+taskId+"/context");
var that = this;
that.setModel(processModel);

54
CPL163

Explanation Screenshot

Note: bpmworkflowruntime is a preconfigured


destination that enable developers to access workflow
service REST APIs. The above task API enables an
application developer to access the process context
using the process instance id.

16. Copy the below code snippet under the section:


//3. Get task description and add it to the
model.

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);
});

});

17. Add the below code snippets under the section:


//4. Create Complete action
var oPositiveAction = {
sBtnTxt: "Confirm",
onBtnPressed: function(e) {
that._triggerComplete(that.oComponentData.inbo
xHandle.attachmentHandle.detailModel.getData().
InstanceID, true, jQuery.proxy(
that._refreshTask, that));
}
};

55
CPL163

Explanation Screenshot

18. Add the below code snippet.


//5. Add Complete action using My Inbox API.

startupParameters.inboxAPI.addAction({
action: oPositiveAction.sBtnTxt,
label: oPositiveAction.sBtnTxt,
type: "Accept"
}, oPositiveAction.onBtnPressed);

19. Add the below code snippet under the section:


//6. Get X-CSRF token and complete task
instance

$.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
});
}
});

Note: Workflow service POST/PATCH APIs are


CSRF protected. A CSRF token is required to
complete the task instance

20. Add the below code snippet under the section:


//7. Update task status to remove the task
instance from SAP My Inbox.

var taskId =
this.getComponentData().startupParameters.taskModel.
getData().InstanceID;
this.getComponentData().startupParameters.inboxAPI.u
pdateTask("NA", taskId);

56
CPL163

Explanation Screenshot

21. Right-click on the editor and select Beautify


option, to align the code

22. Save the changes by click on the Save button on


top-left corner the page.

Note: The save button will look like this:

57
CPL163

Explanation Screenshot

23. Right click on the project and select option:


Deploy  Deploy to SAP Cloud Platform

24. In the deploy popup, select the option button


Deploy a new application

25. Change the Application Name to:


sapcpuiXX
- where XX is your user number

26. Click on Deploy button

58
CPL163

Explanation Screenshot

27. Enter user id and password shared by the trainer x


to deploy the application.

SAP ID: P1942486290

Password: Sap@1234

A successful deployment message will be shown

28. Click Close button

29. From the project, open the workflow model with


name: EmployeeOnboarding_XX where XX is
your user number

59
CPL163

Explanation Screenshot

30. Select ConfirmOrder Message Event

31. Click on the Task speed button and select User


Task speed button

Note: Task speed button will have this icon:

Note: Due to continuous development changes in


the cloud platform, the speed button options might
not appear in the same order as shown in the
screenshot

32. In the User Task Properties, select the


GENERAL tab and enter the Name as
AcceptWorkplace

33. Uncheck the box “Show in inbox workflow log”

Note: This checkbox will hide/unhide the workflow


logs from this task owners.

34. Switch to DISPLAY TEXTS tab and enter the


Subject as:
Accept Workplace for
${context.empData.User.firstName}
${context.empData.User.lastName}

60
CPL163

Explanation Screenshot

35. Switch to RECEPIENTS tab


36. In Users, enter your user name as UserXX where
XX is your user number

37. Switch to USER INTERFACE tab


38. Enter the following:

HTML5 App Name:


sapcpuiXX

Note: replace XX with your user number

Component URL:
AcceptWorkplace

SAPUI5 Component:
demo.sap.com.AcceptWorkplace

61
CPL163

Explanation Screenshot

39. Save the changes by click on the Save button on


top-left corner the page.

Note: The save button will look like this:

40. Select the workflow and right-click


41. Select the option Deploy  Deploy to SAP
Cloud Platform Workflow

Repeat the steps 13 - 29 from section Execute and Monitor Workflow

Repeat the steps 10 - 25 from section Intermediate Message Events

62
CPL163

Explanation Screenshot

42. Click on the REFRESH to get new task


AcceptWorkplace

43. Select the task and click Confirm button to


complete the task.

Note: The workflow instance would be


successfully completed now.

63
www.sap.com/contactsap

© 2017 SAP SE or an SAP affiliate company. All rights reserved.


No part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission of SAP SE or an SAP affiliate company.

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.

You might also like