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: 
Former Member

Hi, my name is Tomer and I'm a developer at SAP HANA Cloud Portal.

One of the most powerful capabilities of this product is an easy integration with SAP back-end systems. In this blog post, I would like to explain how to create a connection between the Cloud Portal and SAP CRM back-end system.

The story behind this scenario is very simple: we want to create a site that contains a simple form. This scenario is to simulate the lead generation process a.k.a web-to-lead, a common scenario across business web sites. NOTE: The following steps are specific for connecting to the CRM back-end system. Similar steps should be applied when connecting to other back-end systems. In addition, in this scenario we do not address the issue of authentication since the site in this scenario is a public site. Propagating the user identity to the back-end would require additional configuration.

First, here is a diagram that should clarify things:

To access an SAP back-end system from the Cloud, an installation of a Gateway server and services are required. In addition, we have to install an SAP Cloud Connector and define the connection between the Gateway service (OnPremise endpoint) and the Cloud Portal instance (Cloud endpoint). And last, we have to define a HANA Cloud destination on the Cloud Portal, pointing to the Gateway service.

Step 1: Create a Gateway Service

The main motivation for using Gateway is to consume SAP back-end systems (such as ERP, CRM) and HANA application data as OData. Gateway converts data to an OData structure, making it possible for any application that consumes OData to use the information easily. In our scenario, we would like to inform the user that the form was successfully submitted. We first have to build a Gateway service using the Service Builder. There are many good tutorials in the web describing how to use the Service Builder. Here are examples for such tutorials: 

•          http://scn.sap.com/community/netweaver-gateway/blog/2012/09/07/the-new-gateway-service-builder-how-t...

•          http://scn.sap.com/people/volker.drees/blog/2012/10/26/step-by-step-guide-to-build-an-odata-service-...

After you finish building the Gateway service, you continue to enabling a secured connection from the cloud using the SAP Cloud Connector.

Step 2: Install and Configure SAP Cloud Connector

We use the SAP Cloud Connector to expose a back-end server in the internet. The Cloud Connector should be installed on a server in the local intranet where the CRM server is located. Follow this detailed tutorial, to install and configure the SAP Cloud Connector: https://help.hana.ondemand.com/help/frameset.htm?e6c7616abb5710148cfcf3e75d96d596.html.

Now that we have a "bridge" between On Premise system and the Cloud, we can consume it using a HANA Cloud destination.

Step 3: Deploy the HANA Cloud Destination to the Cloud Portal Landscape

We use a HANA Cloud destination to fetch remote applications to the Cloud Portal. A destination is a configuration section (described in a properties file) that is deployed to the HANA Cloud application that uses it (Cloud Portal in this scenario). We define the destination properties as follows:


Name=crm__public

URL=https\://proxyi064832trial.hanatrial.ondemand.com:443

Type=HTTP

Authentication=NoAuthentication

Name: the name of the destination. In this scenario, we want to enable fetching the application from a public site, therefore we need to add "__public" (two underscores) suffix to the name of the destination, to enable the Cloud Portal to access it.

URL: the URL that the destination points to. In this case this is the Gateway service that exposes CRM transactions.

Type: in this case, it is HTTP since it's working over HTTP.

Authentication: holds the authentication type that should be used for the application in the URL above. In this scenario this is a public site so no authentication is required.

After we add these lines in the "crm__public" file, we deploy it to the Cloud Portal landscape. This is done using the command line tool that you get as part of the HANA Cloud SDK:


1.          Open command line in "<HANA Cloud SDK folder>/tools".

2.          Execute the following commands for configuring proxy settings (if you are not behind a proxy you can skip this step):


set HTTP_PROXY_HOST=<your HTTP proxy server hostname>

set HTTP_PROXY_PORT=<your HTTP proxy server port>

set HTTPS_PROXY_HOST=<your HTTPS proxy server hostname>

set HTTPS_PROXY_PORT=<your HTTPS proxy server port>

set HTTP_NON_PROXY_HOSTS="localhost"

3.          Execute the following command in order to deploy the destination:

neo put-destination --account <your account> --user <your user name> --provider-account <cloud portal's account> --provider-application <cloud portal's application name> --localpath <path to destination file> --host hanatrial.ondemand.com

You can get more info about this command in the official documentation here:

https://help.hana.ondemand.com/help/frameset.htm?e51558bbbb571014bfc89325eaf075c0.html

Now we have a destination configured, pointing to our CRM back-end. Let's use it now.

Step 4: Write an HTML Form and Send a Request to CRM

This is the last step. We are using a simple HTML form. The main emphasis in this part is on the URL that the form will request on submit. The URL should be in a special format, to instruct Cloud Portal to send the request using the HANA Cloud destination. The format is as follows: "http://dest.crm__public/sap/opu/odata/sap/ZDEMO_LEAD_SRV/Leads".

Let's observe the components of this URL:

"http://dest." is a constant that indicates to the Cloud Portal to use a destination to fetch the data. "crm__public" is the name of the destination to use. "/sap/opu/odata/sap/ZDEMO_LEAD_SRV/Leads" is the path to the Gateway service that exposes the CRM transactions. Every other destination URL in Cloud Portal can be used with the same pattern:

"http://dest.<destination_name>/<path_to_service>".


Here is a sample code that we used to send the request:

/*

* Execute ajax request to backend system using makeRequest

*/

function formSubmitAjax() {

          var url = ' http://dest.crm__public/sap/opu/odata/sap/ZDEMO_LEAD_SRV/Leads';

          var postdata = composePostPayloadJSON();

          var params = {};

          var postdataStr = JSON.stringify(postdata);

          params[gadgets.io.RequestParameters.POST_DATA] = postdataStr;

          params[gadgets.io.RequestParameters.METHOD] = gadgets.io.MethodType.POST;

          var callback = function ajaxCallback(result) {

                    if (result['rc'] === 201) {

                              showFormSuccess();

                    } else {

                              showFormError("Could not connect to CRM system.");

                    }

          };

          if (isValidForm()) {

                    gadgets.io.makeRequest(url, callback, params);

          }

}


This is it! We have a connection to an SAP CRM back-end!

We can now post and get data to and from it.

8 Comments