cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Error 500 while exposing XSJS (consuming CDS)

0 Likes
554

Hi,

   I am facing error 500(Internal Server error) upon executing the following piece of XSJS code. Any help is highly appreciated.

I am extremely new to XSJS, the CDS view works fine standalone.

function getRecord(){

var xsds = $.import("sap.hana.xs.libs.dbutils","xsds");

var ProductOverview = xsds.$importEntity("dev.gls","ar2.ProductOverview");

var Query = ProductOverview.$query();

var Product = Query.$project({

PRODUCT_ID: true,

PRODUCT_NAME: true

});

var result = Product.$execute();

$.response.contentType = "application/json";

$.response.setBody(JSON.stringify(result));

$.response.headers.set('access-control-allow-origin','*');

$.response.status = $.net.http.OK;

result.close();

}

getRecord();

Thanks

Arka

View Entire Topic
pfefferf
Active Contributor
0 Likes

At least the line with "result.close()" has to be removed, cause the result variable is not result set object which has to be closed.

If the importEntity method works depends on the structure of your CDS file. If "ar2" is the CDS file name and aka the name of the root context and "dev.gls" is the package than it is fine.

Because you are importing a CDS View you need to a define a key when you import the entity. This can be done like following:

var ProductOverview = xsds.$importEntity("dev.gls","ar2.ProductOverview", {

PRODUCT_ID: { $key: true }

});

Regards,

Florian

PS: By the way, this post should be moved to the SAP HANA Dev Center space, cause it is not really related to SAP Gateway.

0 Likes

Hi Florian,

               Will try the suggested steps and keep you posted. Will close this discussion as per your suggestion and open one in the mentioned forum.

Thanks

Arka