‎2024 Nov 29 1:12 PM
Hello,
all my SELECT's of .drafts entities are failing as .dafts is undefined.
working with sap/cds 8.5.0.
Anybody else the problem. Using a string representation works... but is ugly 😉
‎2024 Nov 30 1:22 PM - edited ‎2024 Nov 30 1:22 PM
Hi @T1mey ,
Have you thought about providing more information and/or code example on how your model, service and the SELECT statement looks like? In my experience, in most of the cases this may speed up the process of finding out what the exact case is.
I tried with "@sap/cds": "^8.5.0" in the following ways, both worked.
service implementation variants:
class MyService extends cds.ApplicationService {
init() {
const { MyServiceEntity } = this.entities;
(async () => {
const res = await SELECT.from(MyServiceEntity.drafts);
})();
this.on('READ', MyServiceEntity, async (req) => {
await SELECT.from(MyServiceEntity.drafts);
});module.exports = cds.service.impl(async function (srv) {
const { MyServiceEntity } = this.entities;
(async () => {
const res = await SELECT.from(MyServiceEntity.drafts);
})();
srv.on('READ', MyServiceEntity, async (req) => {
await SELECT.from(MyServiceEntity.drafts);
});
service.cds
using { my.namespace as db } from '../db/schema';
service MyService {
entity MyServiceEntity as projection on db.MyDbEntity;
}
annotate MyService.MyServiceEntity with @odata.draft.enabled;
db.schema
entity MyDbEntity {
key ID: Integer;
}
Regards,
Peter
‎2024 Dec 02 6:57 AM
THanks for your reply. It showed my the reason...
As we're using storyboard, which needs "@sap/low-code-event-handler": "^1.2.4"
my handler class is auto generated and the calls are delegated to a js file.
In those files I can't work with this.entities. So I need cds.entities and for accessing it in that way I always get undefined for <Entity>.drafts
Any idea how to overcome this?
‎2024 Dec 03 8:49 AM
Hi @T1mey
I see no options to access service entities through cds unfortunately.
One can only access db entities, but there is no drafts in that layer.
Maybe if somehow you can access the service module in your delegate, and use serviceModule.entites?
Regards,
Peter