Skip to Content
Technical Articles
Author's profile photo Rima Yadav

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.

  1. Create Custom CDS view replication for SAP S/4HANA Cloud by selecting the necessary fields:
    1. Logon to SAP Fiori launchpad as SAP S/4 HANA Administrator.
    2. Launch the ‘Custom CDS Views’ application.
    3. 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.
    4. Click ‘Add’ and then click ‘Add Primary Data Source’.
    5. In this case, we will add ‘I_WorkforcePerson’ CDS view replication as ‘Primary Data Source’. Search and select ‘I_WorkforcePerson’ and then click ‘Add’.

    6. 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)
    7. Now click on ‘Publish’ which will publish our CDS view replication for SAP S/4HANA Cloud.       
    8. Click ‘Preview’ to see the display result of our published CDS view replication.
  2. Create Custom Communication Scenario for this CDS view replication :
    1. Launch the ‘Custom Communication Scenarios’ application.
    2. Click the ‘New’ button.
    3. Enter ‘Communication Scenario ID’ (for example, YY1_EMAILIDMAPPING_SCEN) and ‘Description’ for your Communication Scenario, and click ‘New’.
    4. On the ‘Inbound Services’ tab, click ‘+’:
    5. Search for the CDS view replication for SAP S/4HANA Cloud which we published in step 1, select the checkbox and click ‘OK’.
    6. 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:
  3. 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.

    1. To create a Communication User and Communication System, you follow the steps in the given link:
    2. 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.
  4. 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:
  5. 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 = "$filter=PersonExternalID eq 'TEST_ADMIN' &$format=json"; 
    	var result = {
    	}; {
    		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:

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!

Assigned Tags

      You must be Logged on to comment or reply to a post.
      Author's profile photo Steven De Baerdemaeker
      Steven De Baerdemaeker

      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.

      "<html><head><meta http-equiv="cache-control" content="no-cache" /><meta http-equiv="pragma" content="no-cache" /></head><body onload="javascript:var url=window.location.hash;if(url&&(0!==url.length)){document.cookie=&quot;oucfarwtevzodseqoredaobbcuozbfzwrctxwza_anchor=&quot;+escape(url)+&quot;; path=/&quot;}document.forms[0].submit()"><noscript><p><strong>Note:</strong> Since your browser does notsupport JavaScript, you must press the Continuebutton once to</p></noscript><form method="POST" action="https://**********"><input type="hidden" name="SAMLRequest" value="HIDDENSECRETMTYSAMLTHINGYzZTU5L=="><input type="hidden" name="RelayState" value="oucfarwtevzodseqoredaobbcuozbfzwrctxwza"><noscript><input type="submit" value="Continue"></noscript></form></body></html>"

      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:

      Author's profile photo Rima Yadav
      Rima Yadav
      Blog Post Author

      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?

      Author's profile photo Steven De Baerdemaeker
      Steven De Baerdemaeker

      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.