We have already published serveral blogs talking about SAP Business One version for SAP HANA new Service Layer oData interface:

B1 Service Layer with JavaScript – Handling B1 Objects without .Net (nor DI API)

How to bind SAP Business One Apps on HANA to Tables and Views?

In this blog I’ll like to continue the series by talking about how to enable CORS (Cross Origin Resource Sharing) in Service Layer.

If you want to better understand CORS just have a look to the web, many articles are available. Here I just gave one link talking about it:

Using CORS – HTML5 Rocks</title> <meta name="description" content="An introduction to Cross Ori…

CORS configuration has been implemented in Service Layer since SAP Business One version for SAP HANA 9.1 PL08 released end of July 2015 and is documented inside the document “Working_with_SAP Business_One_Service_Layer.pdf” directly available from your HANA Server at https://hanaserver:50000/Working_with_SAP_Business_One_Service_Layer.pdf.

In order to enable CORS in your Service Layer server you have to add the following 2 parameters into the b1s.conf file located at /usr/sap/SAPBusinessOne/ServiceLayer/conf folder:

“CorsEnable” : true

Default value is false.

If this item is set to true, Service Layer will check the value of

CorsAllowedOrigins.

“CorsAllowedOrigins”:”http://servername1:port1;http://servername2:port2

This item takes effect only if CorsEnable is true. It is a semi-colon separated

string list where each string is a representation of a trusted origin.

CorsAllowedOrigins can also be configured as “*” to support requests from

all origins. However, in production environments, it is not recommended due to

security issues.

After changing the configuration don’t forget to restart Service Layer!

Now that Service Layer CORS has been configured you can for example directly call Service Layer from your client side Java Script application. You just need to add to your ajax calls the parameter:

        xhrFields: {

              withCredentials:true

        },

I have published here a very simple HANA XS application (same one Ralph published in the blog B1 Service Layer with JavaScript – Handling B1 Objects without .Net (nor DI API) but just running inside HANA XS engine). Just import this XS app into your HANA server and learn how to develop a client side Java Script application connecting directly to Service Layer.

Hope you will enjoy it!

Trinidad.

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply