Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
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: https://help.sap.com/viewer/c2f4816a64a642528989c94d3fb91d92/SHIP/en-US/803025fec0ed4bfbb62d5e0acbef...

    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 = "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');
    }
    });

    Output:




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!
3 Comments