Hi colleagues!
We have one simple CDS:
namespace training.szharko.edu.RHINE; @Schema: 'SZHARKO' context test1 { entity rhine_test { key ID : Integer; Name : String(80); Raiting : Association to raiting { ID } ; Date: LocalDate; Val : Integer64; CountryID : Integer; }; entity raiting { key ID : Integer; Name : String(80); }; entity country { key ID : Integer; Name : String(80); }; };
CDS tables contain the following data:
insert into "SZHARKO"."training.szharko.edu.RHINE::test1.rhine_test" values(1,'Alice',1,'',1,1); insert into "SZHARKO"."training.szharko.edu.RHINE::test1.rhine_test" values(2,'Petr',2,'2015-01-15',10,1); insert into "SZHARKO"."training.szharko.edu.RHINE::test1.rhine_test" values(3,'Petr',3,'2015-01-15',10,2); insert into "SZHARKO"."training.szharko.edu.RHINE::test1.rhine_test" values(4,'Alex',2,'2015-01-01',20,3); insert into "SZHARKO"."training.szharko.edu.RHINE::test1.country" values(1,'Germany'); insert into "SZHARKO"."training.szharko.edu.RHINE::test1.country" values(2,'Belarus'); insert into "SZHARKO"."training.szharko.edu.RHINE::test1.country" values(3,'Russia'); insert into "SZHARKO"."training.szharko.edu.RHINE::test1.raiting" values(1,'One'); insert into "SZHARKO"."training.szharko.edu.RHINE::test1.raiting" values(2,'Two'); insert into "SZHARKO"."training.szharko.edu.RHINE::test1.raiting" values(3,'Three'); insert into "SZHARKO"."training.szharko.edu.RHINE::test1.raiting" values(4,'Four'); insert into "SZHARKO"."training.szharko.edu.RHINE::test1.raiting" values(5,'Five');
1) In the first case I create simple XSJS file with built-in association. But it doesn't work with field "CountryID.Name"
$.import("sap.hana.xs.libs.dbutils", "xsds"); var XSDS = $.sap.hana.xs.libs.dbutils.xsds; var SoHeader = XSDS.$importEntity("training.szharko.edu.RHINE", "test1.rhine_test", { items: { $association: { $entity: "training.szharko.edu.RHINE::test1.raiting" , $on: "$SOURCE.\"items\".\"ID\" = $SOURCE.\"Raiting\".\"ID\"" } } } , { country: { $association: { $entity: "training.szharko.edu.RHINE::test1.country" , $on: "$SOURCE.\"country\".\"ID\" = $SOURCE.\"CountryID\"" } } } ); var query = SoHeader.$query(); var query2 = query.$project({ Name: true, Raiting: {ID : true, Name : true}, CountryID: {Name: true}}); var query4 = query2.$execute(); var query5 = query2.$sql(); $.response.setBody(JSON.stringify(query4));
2) In the second case it doesn't work field "Val" (null value):
$.import("sap.hana.xs.libs.dbutils", "xsds"); var XSDS = $.sap.hana.xs.libs.dbutils.xsds; var SoHeader = XSDS.$importEntity("training.szharko.edu.RHINE", "test1.rhine_test", { items: { $association: { $entity: "training.szharko.edu.RHINE::test1.raiting" , $on: "$SOURCE.\"items\".\"ID\" = $SOURCE.\"Raiting\".\"ID\"" } } } , { country: { $association: { $entity: "training.szharko.edu.RHINE::test1.country" , $on: "$SOURCE.\"country\".\"ID\" = $SOURCE.\"CountryID\"" } } } ); var query = SoHeader.$query(); var query2 = query.$project({ ID : true, Name: true, Raiting: {ID : true}, Date: true, Val : true}); var query4 = query2.$execute(); var query5 = query2.$sql(); $.response.setBody(JSON.stringify(query4));
Help me, please, how can I display field "CountryID.Name", not changing CDS file and field "Val" with "Integer64" type.
Thank you in advance!