Technical Articles
SAP Cloud Integration with Workflow and Business Rule
Introduction:
In this blog post, I will explain how to use cloud integration with workflow for a simple credit card request scenario. In this workflow, I will use business rule to get the credit card tier (i.e. Gold/Platinum/Silver) based on requestor’s level in organisation’s hierarchy.
Scenario:
- An employee will raise a credit card request. This is mimicked using Postman.
- The message will go to the cloud integration flow (capability within SAP Integration Suite).
- The cloud integration flow will format the message as required by workflow and specify which particular workflow instance and business rule need to be executed.
- In this workflow, initial input context will contain only employee ID information.
- The first service task will fetch the required information for that employee (i.e. Name, Position, Contact no. etc.)
- The second service task will call the business rule (capability with SAP Workflow Management) to find which credit card tier the requestor is eligible for.
- A user task will be sent to the finance team for approval. Finance team can upgrade or downgrade the credit card tier. In case of rejection, it is recommended to specify reasons for rejection.
- A mail will be sent to the requestor regarding approval or rejection. Rejection mail will contain the reason for rejection. For this experiment, I am using my email id to get the mails.
Prerequisite Setup:
Three subscriptions are required in the BTP trial.
- SAP Business Application Studio: To create workflow (Reference Link: https://developers.sap.com/tutorials/cp-workflow-2-create-module-cf.html)
- Workflow Management: To monitor deployed workflow/workflow instance and create Business Rule. (Reference Link: https://developers.sap.com/tutorials/cp-starter-ibpm-employeeonboarding-1-setup.html#ae14368a-03fb-42fe-841b-e8d94b5dd98e)
- Integration Suite : To create Integration flow in Cloud Integration (Reference Link: https://developers.sap.com/tutorials/cp-starter-isuite-onboard-subscribe.html)
Design Solution:
Workflow Creation:
Workflow
Step 1:
Create a service task to fetch employee details based on employee ID.
Service Task
Create a destination named ‘EmpServ’ in BTP Cockpit containing base URL and authentication details.
Step 2:
Prepare required message format for calling Business Rule to get tier details based on Employee level using JS in ‘Script Task’.
var requestData = {
request: {
RuleServiceId: $.context.brmId,
Vocabulary: [
{
EmpLevel: {
level: $.context.EmpDetails.ReportsTo,
},
},
],
},
};
$.context.requestData = requestData;
Step 3:
Call Business Rule using ‘Service Task’ step.
Service Task
Step 4:
Create a ‘User task’ step for finance team approval. User interface is of type ‘Form’.
Step 5:
Use below JS in ‘Script Task’ to set the decision in context.
var decision = $.usertasks.usertask1.last.decision;
$.context.decision = decision;
Step 6:
Use ‘Exclusive Gateway’ to execute the ‘Approve’ or ‘Reject’ path.
Condition for approval path: ${context.decision == “approve”}
Condition for rejection path: set as Default
Step 7:
Use ‘Mail Task’ to send approval or rejection mail.
In BTP cockpit, configure destination for Mail. Below is the template for mail destination.
Type=MAIL
Name=bpmworkflowruntime_mail
mail.user=
mail.password=
mail.smtp.host=mail.example.com
mail.smtp.port=587
mail.transport.protocol=smtp
mail.smtp.starttls.required=true
mail.smtp.starttls.enable=true
mail.smtp.auth=true
mail.smtp.from=cpworkflow@example.com
Reference Link for Mail Destination creation: https://help.sap.com/viewer/cca91383641e40ffbe03bdc78f00f681/Cloud/en-US/6442cb4f8b0f41178abce14c35f5def4.html
Step 8:
Deploy MTA Archive.
Business Rule:
Step 1:
Go to Workflow Management -> Manage Project Rules (Under Development tools) -> Create Project
Step 2:
Create two local data objects: EmpLevel (Usage: Input) and Output (Usage: Result)
Local Data Object for Input
Local Data Object for Result
‘Tier’ attribute is associated with value help.
Value List for Tier
Step 3:
Create Rule to determine tier based on employee level.
Decision Table
Step 4:
Create RuleSet and Rule Service.
Step 5:
Deploy Rule Service to Cloud Runtime.
Reference Link for step by step creation of Business Rule and testing: https://developers.sap.com/mission.cp-rules-get-started.html
Cloud Integration:
Navigation Path:
Go to SAP Integration Suite -> Cloud Integration
IFLOW
Step 1:
Configure sender channel as below.
Sender Channel
Step 2:
Configure ‘Content Modifier’ as below.
Message Header
Exchange Property
Message Body
Step 3:
Configure Receiver Channel as below.
Receiver Channel
Step 4:
Create OAuth2 Client credentials in Security Material.
OAuth2 Client Credentials
Test Execution:
Step 1:
Trigger message using Postman tool to the cloud integration flow endpoint.
Postman
Step 2:
Approve/Reject Credit card request from Workflow Management -> Productivity tools -> My Inbox.
Task
Before approving, let’s change the Tier to ‘Platinum’ from the dropdown list.
Step 3:
Mail notification is received.
Approval Email
Summary:
- To initiate workflow from Cloud integration, ‘workflow_rest_url’ is used, which can be found by viewing the ‘Service Key’ details of the deployed workflow instance in BTP cockpit.
- ‘Rule Execution API for Cloud Foundry’ available in SAP API Business Hub is used to invoke Rule Service from Workflow Service Task.
- Rule Service ID and Workflow Definition ID are used as ‘Externalized Parameters’ in IFLOW to keep the flow dynamic.
Thank you for reading this blog post. Hope this helps. Please feel free to share your feedback or thoughts in a comment or ask questions in the below Q&A tag.
https://answers.sap.com/tags/73555000100800000287
Regards,
Priyanka Chakraborti
Great blog, thanks a lot for sharing.
Thank you 🙂
excellent blog can i get the code snippet
Thanks. The code snippet is already present in the blogpost. Anything specific you are looking for? Sorry for late response.
good one
Thanks
This is awesome blog/info, thank you!
Thank you Tom 🙂
Hi Priyanka,
I followed your blog, when test the IFlow from postman, it failed. I have follow question.
1: in postman, which authorization type should choose?
2: in postman, should send post request or get request?
Tried a lot for above two points with different ways, but all failed, could you please share your detail information for postman call IFlow?
Thanks.
Thank you for your answer. I follow below step but got error with status 403 forbidden. Could you please kindly take a look what’s wrong with my below steps?
1 get Process Integration Runtime instance service client id and client secret to get access token.
Send get request with above client Id and client secret to get access token.
2 send post request with OAuth 2.0 and the above access token to send post request, but get 403 errors
403 means unauthorised.
Thank you, how to check if the instance that created for Process Integration Runtime has the role 'ESBMessaging.send? I can only find role collection/role for user.
Hi Frank,
If the role is not visible, please create a new instance. Then make sure you assign esbmessaging.send role during instance creation process. Generally, it is the default setting. Then create service key. Use client ID as username and client secret as password.
Thank you, after recreate integration process instance, issue fixed.
Glad to hear that.
Nice blog Priyanka
Thanks
Hi Priyanka,
Thank you for this blog. However, I have one doubt, regarding the step 4: Create OAuth2 Client credentials in Security Material.
You state that some parameters can be found in the service key within the deployed workflow instance, but in our case, the wokflow was deployed a few months ago, and I cannot find these parameters, could you detail in which part of the workflow are these, please?
Kind regards,