Technical Articles
How to create Custom CDS view replication for SAP S/4HANA Cloud and consume it as an OData API in SAP Intelligent RPA process bots
This blog post aims to provide a solution to a common issue that occur while consuming CDS view replication for SAP S/4HANA Cloud as an API in SAP Intelligent RPA process bots.
For example, let’s take a scenario, where we want to find out the workforce person related information like e-mail ID of an employee using the External ID of the person.
For this we have one whitelisted CDS view replication for SAP S/4HANA Cloud that provides the mapping between the External ID and the e-mail ID of an employee.
The following steps must be done in order to expose the CDS view replication as OData Service (API) in SAP S/4HANA Cloud System. These services are being consumed by the SAP Intelligent RPA bots for SAP S/4HANA processes.
- Create Custom CDS view replication for SAP S/4HANA Cloud by selecting the necessary fields:
- Logon to SAP Fiori launchpad as SAP S/4 HANA Administrator.
- Launch the ‘Custom CDS Views’ application.
- Click the ‘Create’ button and then provide a ‘Name’ of the Custom CDS view replication and check the ‘External API’ checkbox. The general naming convention for this starts with ‘YY1_’ which is prefixed automatically.
Note: By selecting the ‘External API’ checkbox, you activate the CDS view replication for SAP S/4HANA Cloud for consumption through OData API. - Click ‘Add’ and then click ‘Add Primary Data Source’.
- On the Field Selection tab,check the ‘Select’ checkbox for all the fields which we want to view based on the scenario. In this case we will select the following fields:
• PersonExternalID
• FirstName
• BusinessPartnerUUID (expand the associated field _WorkplaceAddress and then select key field BusinessPartnerUUID of I_WorkplaceAddress)
• DefaultEmailAddress (expand the associated field _WorkplaceAddress and then select the DefaultEmailAddress field) - Now click on ‘Publish’ which will publish our CDS view replication for SAP S/4HANA Cloud.
- Click ‘Preview’ to see the display result of our published CDS view replication.
- Create Custom Communication Scenario for this CDS view replication :
- Launch the ‘Custom Communication Scenarios’ application.
- Click the ‘New’ button.
- Enter ‘Communication Scenario ID’ (for example, YY1_EMAILIDMAPPING_SCEN) and ‘Description’ for your Communication Scenario, and click ‘New’.
- On the ‘Inbound Services’ tab, click ‘+’:
- Search for the CDS view replication for SAP S/4HANA Cloud which we published in step 1, select the checkbox and click ‘OK’.
- Click ‘Publish’ to publish the communication scenario.
Note: Publishing the communication scenario might take some time.Once it is published successfully, we will get a notification and the status will change to ‘Published’ as shown in below snapshot:
- Setup Communication Management for this Communication Scenario:
You need to create a Communication User, Communication System and a Communication Arrangement with the Communication Scenario created in Step 2.- To create a Communication User and Communication System, you follow the steps in the given link: https://help.sap.com/viewer/c2f4816a64a642528989c94d3fb91d92/SHIP/en-US/803025fec0ed4bfbb62d5e0acbef9de3.html
- To create Communication Arrangement:
- Launch the Communication Arrangements application and then click New.
- To create a communication arrangement for the custom communication scenario (YY1_EMAILIDMAPPING_SCEN), select the communication scenario you created in step 2.
- In the Common Data section, select the Communication System that was created in step 3.i.
The communication user that was created in the previous step is automatically added to the Inbound Communication section. - Click ‘Save’ to save your changes.
- In the Inbound Services section of the communication arrangement, we can see the Service URL to call our CDS view replication for SAP S/4HANA Cloud via oData.
- Consuming the CDS view replication for SAP S/4HANA Cloud as a Service using postman:
This Service URL link can be accessed directly through the web browser or postman and the authentication would be done with the help of our Communication User created as part of Communication Management setup in step 3.
Copy this entity name YY1_EMAILIDMAPPING and append it in the Service URL to see the data inside it as shown below:
- Consuming the CDS view replication for SAP S/4HANA Cloud as a Service in Intelligent RPA process bots:
This Service can now be used in our Intelligent RPA process bots. For more details, refer the below code snippets.// Code snippet for hitting the API var url = "https://SystemDomain.com/sap/opu/odata/sap/YY1_EMAILIDMAPPING_CDS/YY1_EMAILIDMAPPING?$filter=PersonExternalID eq 'TEST_ADMIN' &$format=json"; var result = { }; ctx.ajax.call( { method: e.ajax.method.get, url: url, async: true, contentType: e.ajax.content.json, headers: { 'Authorization': 'Basic ' + ctx.base64.encode('<Communication User>'+ ':' +'<Password>') }, //Success handler for CDS view data fetching success: function (res, status, xhr) { result = xhr; var responseValue = ctx.json.parse(result.responseText).d; var EmailID = responseValue.results[0].DefaultEmailAddress; // logging the email id fetched from the published CDS view ctx.log("Email ID of TEST_ADMIN is : "+EmailID); }, //Error handler for CDS view data fetching error: function (res, status, xhr) { ctx.log('Error Message'); } });
Similarly, any whitelisted CDS view replication could be published and consumed.
By following the above steps and code snippets, you will be able to consume Custom CDS view replication for SAP S/4HANA Cloud in SAP S/4HANA process bot.
Below are the template bots having CDS view replication call:
- 49B- Mass Change of Project Roles for Commercial Projects
- 4JF- Automated List of Ongoing Projects, Purchase Requisitions and Purchase Orders for Terminated Employees
Try this out and do share your comments if you face any challenges.
Stay tuned for more technical blog post related to SAP S/4HANA process automation content!
We encounter some issues, when doing GET (from within iRPA and using S4H Cloud Essentials).
The response is “OK”, with status 200, but the responseText is a HTML webpage, including a message that Javascript is not enabled.
Fetching a CSRF token using method HEAD and performing POST’s sending the SAP cookie and CSRF also works fine, but executing GET methods does not seem to work at all.
Using postman the GET’s work fine with the same url and credentials or other development environments do work fine, it is just iRPA that is failing.
I also tried adding -api to the instance, which is working for postman, but it's not working for iRPA.
Am using the latest IRPA release: 2.0.3.97
Hello Steven,
Ideally the error mentioned above is because of Invalid communication user/Password while calling the API.
Also, for CDS views only Get/Head method is allowed not the post method.
Can you please share some more information on what you are using, is it an oData API or an published CDS View?
Thank you, Rima. The problem was indeed related to the communication user. It was postman itself that pointed us in the wrong direction by reusing browser cookies, allowing to let the communication to work, while instead it should have failed.