Empowering business users to create new workflows with S/4HANA Cloud, public edition and SAP BTP – Part 2
This is the second blog in a three part series demoing SAP Build Process Automation (SBPA) along with SAP Build app to call an API in SAP S/4HANA Cloud, public edition (S/4HC). To recap, the app allows end users to enter basic information about a new project and submission triggers an approval workflow on SBPA. After approval, a call to S/4HC is made to create the project with the data submitted and a default set of work packages. In part 1 of this series, I covered how to create a REST API integration flow on BTP Cloud Integration to handle the API for SBPA and subsequent API mapping for S/4HC. In this blog, I’ll cover the SBPA setup to handle the approval workflow and call to the REST API on BTP CI via an Action.
There are 3 main steps required for SBPA.
- Create BTP Destination for BTP CI REST Endpoint
- Create an Action to handle the API call to BTP CI.
- Create the Business Process to handle call from SAP Build app, approval workflow forms, and incorporate action call.
Note: There are also other blogs/tutorials that can be referenced for more information on adding actions to process automations including this one.
Create BTP Destination for SAP BTP Cloud Integration
A BTP destination is needed in order for SBPA to connect to our REST API. An example outlining the process to create a destination is documented here.
The Client ID, Client Secret and Token Service URL are found in the service instance key of your BTP CI subaccount.
You can find the REST endpoint when you deploy your integration under the Operations View->Manage Integration Content. You can remove the /clientproject from the end of the URL which then produces a value: https://<subaccount>-rt.cfapps.sap.hana.ondemand.com/http/
The following additional properties should be added to use the destination in SAP Build:
- sap.processautomation.enabled = true
- sap.applicationdevelopment.actions.enabled = true
Create Action for REST API
Note: an end to end tutorial for Action creation can be found here.
An OpenAPI Specification is needed in order to create the action based on the REST endpoint created in the first blog. I created this file by using chatGPT to generate the specification based on the JSON payload that was used to build the iFlow. To keep things simple, I used all String datatypes but if you wanted to perform validations you could correctly set the datatypes.
Navigate to the SAP Business Process Automation app on BTP and select Build an Automated Process.
Next click on Actions to create a new Actions project.
Give your project a name and description and provide the OpenAPI file created in the previous step.
Add the POST action
Next, you’ll want to enable CSRF for the action via Settings in the upper left.
You can modify any API fields that you need to in the Action or default fields.
In order to verify that our Action works correctly, we can test it right from the project by clicking on Test and inputting some test data. A successful test should result in a HTTP 201 response, which it does in this case.
Verifying that the call worked end to end, I can see the newly created project in S/4HC by querying the projects API in S/4HC directly from Postman.
Once testing is complete, the Action can be released and published.
Create Business Process
The destination needs to be added to SBPA before creating the Business Process. In the Build lobby, navigate to settings and you should see a popup to add the destination.
Now it’s time to create the Business Process.
After creating the new Business Process, create a new Data Type with fields matching the JSON payload for the project data.
Next, create a new API trigger for the Business Process.
Next, assign the projectData Data Type as an Input to the process under Process Details.
An approval form is added next. I’ve kept the form short for the purposes of this demo, only using 3 fields for input and allowing the approver to enter a rejection reason if the project is not approved.
In addition, the email details are set for the Approver. In this demo, I have hardcoded the Approver to be my email address and allowed 3 days for approval.
From the Reject port, add a Send Mail step and provide the Reject details. You can set who the message should be sent to and provide the body of the email as well, including the Rejection reason from the Approval Form.
Now it is time to add our Action. From the Approve port on the Form select Actions -> Browse library.
Search for the Project Action and click Add.
After naming the action, the Process Content fields are mapping as Inputs to the Action:
After the action call, we add a Send Mail step to notify the end user that their project was approved. The response fields can be used for the project details.
The end result is a simple Process that looks like the following:
With the process complete, it is time to Build and Deploy the project:
Testing the New Process
With the process deployed, we can test it from Postman. The process details can be found under the Process Monitor:
OAuth authentication is used for authentication to the process:
The project data is submitted to SBPA and a successful 201 HTTP code is returned. The end result is that a new task is generated for the approver.
Viewing My Inbox on BTP, I can see that I have a new approval request. The task is approved by clicking the Approve button.
The end user receives an email that the project has been approved and is created. You can add additional data to this email, for example you could add a link to S/4HC and have the user open the project details directly.
The project is now in S/4HC with the default set of work packages ready to be used:
Now we have a fully functioning (and tested) business process with an approval workflow and a successful API call to SAP S/4HANA Cloud, public edition via an Action.
In the next blog, a UI will be created in SAP Build App that end users can use to submit their project data. In this blog, we simulated this step using Postman.
Let me know if you have any questions in the comments.