Skip to Content
Technical Articles
Author's profile photo Priyanka Chakraborti

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:

  1. An employee will raise a credit card request. This is mimicked using Postman.
  2. The message will go to the cloud integration flow (capability within SAP Integration Suite). 
  3. 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.
  4. In this workflow, initial input context will contain only employee ID information.
  5. The first service task will fetch the required information for that employee (i.e. Name, Position, Contact no. etc.)
  6. 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.
  7. 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.
  8. 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.

  1. SAP Business Application Studio: To create workflow (Reference Link: https://developers.sap.com/tutorials/cp-workflow-2-create-module-cf.html)
  2. 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)
  3. 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

Workflow

Step 1:

Create a service task to fetch employee details based on employee ID.

Service%20Task

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%20Task

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%20Object%20for%20Input

Local Data Object for Input

Local%20Data%20Object%20for%20Result

Local Data Object for Result

‘Tier’ attribute is associated with value help.

Value%20List%20for%20Tier

Value List for Tier

Step 3:

Create Rule to determine tier based on employee level.

Decision%20Table

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

IFLOW

Step 1:

Configure sender channel as below.

Sender%20Channel

Sender Channel

Step 2:

Configure ‘Content Modifier’ as below.

Message%20Header

Message Header

Exchange%20Property

Exchange Property

Message%20Body

Message Body

Step 3:

Configure Receiver Channel as below.

Receiver%20Channel

Receiver Channel

Step 4:

Create OAuth2 Client credentials in Security Material.

OAuth2%20Client%20Credential

OAuth2 Client Credentials

Test Execution:

Step 1:

Trigger message using Postman tool to the cloud integration flow endpoint.

Postman

Postman

Step 2:

Approve/Reject Credit card request from Workflow Management -> Productivity tools -> My Inbox.

Task

Task

Before approving, let’s change the Tier to ‘Platinum’ from the dropdown list.

Step 3:

Mail notification is received.

Email

Approval Email

 

Summary:

  1. 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.
  2. ‘Rule Execution API for Cloud Foundry’ available in SAP API Business Hub is used to invoke Rule Service from Workflow Service Task.
  3. 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

 

Assigned Tags

      19 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Frank Li
      Frank Li

      Great blog, thanks a lot for sharing.

      Author's profile photo Priyanka Chakraborti
      Priyanka Chakraborti
      Blog Post Author

      Thank you 🙂

      Author's profile photo DEO DEO
      DEO DEO

      excellent blog can i get the code snippet

      Author's profile photo Priyanka Chakraborti
      Priyanka Chakraborti
      Blog Post Author

      Thanks. The code snippet is already present in the blogpost. Anything specific you are looking for? Sorry for late response.

      Author's profile photo Soumyadip Chakraborty
      Soumyadip Chakraborty

      good one

      Author's profile photo Priyanka Chakraborti
      Priyanka Chakraborti
      Blog Post Author

      Thanks

      Author's profile photo Tom Zhao
      Tom Zhao

      This is awesome blog/info, thank you!

      Author's profile photo Priyanka Chakraborti
      Priyanka Chakraborti
      Blog Post Author

      Thank you Tom 🙂

      Author's profile photo Frank Li
      Frank Li

      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.

      Author's profile photo Priyanka Chakraborti
      Priyanka Chakraborti
      Blog Post Author
      1.  OAuth2 client credentials ( Cloud foundry environment)
      2. POST
      Author's profile photo Frank Li
      Frank Li

      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

       

      Author's profile photo Priyanka Chakraborti
      Priyanka Chakraborti
      Blog Post Author

      403 means unauthorised.

      1. Can you please check if the instance that you created for Process Integration Runtime has the role 'ESBMessaging.send'?
      2. To simplify the trigger from Postman, You can also use basic authentication directly. Username will be client id and password will be client secret.

       

       

      Author's profile photo Frank Li
      Frank Li

      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.

      Author's profile photo Priyanka Chakraborti
      Priyanka Chakraborti
      Blog Post Author

      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.

      Author's profile photo Frank Li
      Frank Li

      Thank you, after recreate integration process instance, issue fixed.

      Author's profile photo Priyanka Chakraborti
      Priyanka Chakraborti
      Blog Post Author

      Glad to hear that.

      Author's profile photo prashanth pundalik
      prashanth pundalik

      Nice blog Priyanka

      Author's profile photo Priyanka Chakraborti
      Priyanka Chakraborti
      Blog Post Author

      Thanks

      Author's profile photo Laura Sanguino
      Laura Sanguino

      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,