on 2016 Aug 05 9:37 AM
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
Request clarification before answering.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 6 | |
| 6 | |
| 4 | |
| 4 | |
| 3 | |
| 3 | |
| 2 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.