Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

SAP CAP nodeJS .drafts undefined

T1mey
Active Participant
0 Likes
1,207

Hello,

all my SELECT's of .drafts entities are failing as .dafts is undefined.

T1mey_0-1732885842495.png

working with sap/cds 8.5.0.

Anybody else the problem. Using a string representation works... but is ugly 😉

3 REPLIES 3
Read only

catano
Active Participant
0 Likes
1,139

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

Read only

T1mey
Active Participant
0 Likes
1,087

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?

Read only

catano
Active Participant
0 Likes
1,062

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