cancel
Showing results for 
Search instead for 
Did you mean: 

Error while creating deeply nested entity

Mathias-Storm
Discoverer
0 Kudos

Context:

I am building a CAP application to manage Ressource Rentals. I also created an annotation-based fiori app to go along with it. These are the entities:

entity Resources : managed, cuid {
name : String;
description : String;
type : Association to ResourceTypes;
rentals : Association to many Rentals
on rentals.resource = $self;
}
entity Rentals : managed, cuid {
resource : Association to Resources;
start : DateTime;
end : DateTime;
}

And this is the corresponding service:

service ResourceService {
entity Resources as projection on my.Resources;
annotate Resources with @odata.draft.enabled;
entity Rentals as projection on my.Rentals;
annotate Rentals with @odata.draft.enabled;
}

In my Fiori app, i created a list report page and added a table to the ressources.

I linked those to the rentals. This works so far, i can now browse ressources and see their rentals.

Problem:

When i edit a ressource and create a new rental in the rentals table on the object page, i get the following error in CAP:

[cds] - ️Uncaught TypeError: Cannot read properties of undefined (reading 'ID')
at UriHelper.buildEntityKeys (C:\Projects\rentals\node_modules\@sap\cds\libx\_runtime\cds-services\adapter\odata-v4\okra\odata-server\utils\UriHelper.js:85:22)
at ResponseHeaderSetter.setLocationHeader (C:\Projects\rentals\node_modules\@sap\cds\libx\_runtime\cds-services\adapter\odata-v4\okra\odata-server\core\ResponseHeaderSetter.js:102:17)
at SetResponseHeadersCommand.execute (C:\Projects\rentals\node_modules\@sap\cds\libx\_runtime\cds-services\adapter\odata-v4\okra\odata-server\invocation\SetResponseHeadersCommand.js:66:30)
at CommandExecutor._execute (C:\Projects\rentals\node_modules\@sap\cds\libx\_runtime\cds-services\adapter\odata-v4\okra\odata-server\invocation\CommandExecutor.js:71:17)
at C:\Projects\rentals\node_modules\@sap\cds\libx\_runtime\cds-services\adapter\odata-v4\okra\odata-server\invocation\CommandExecutor.js:81:18
at ConditionalRequestControlCommand.execute (C:\Projects\rentals\node_modules\@sap\cds\libx\_runtime\cds-services\adapter\odata-v4\okra\odata-server\invocation\ConditionalRequestControlCommand.js:48:5)
at CommandExecutor._execute (C:\Projects\rentals\node_modules\@sap\cds\libx\_runtime\cds-services\adapter\odata-v4\okra\odata-server\invocation\CommandExecutor.js:71:17)
at C:\Projects\rentals\node_modules\@sap\cds\libx\_runtime\cds-services\adapter\odata-v4\okra\odata-server\invocation\CommandExecutor.js:81:18
at C:\Projects\rentals\node_modules\@sap\cds\libx\_runtime\cds-services\adapter\odata-v4\okra\odata-server\invocation\DispatcherCommand.js:88:11
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
id: '1521876',
level: 'ERROR',
timestamp: 1701680136247
}

There is no custom logic associated with the service. I have tried creating one and calling super.init() in the init() callback, but that did not change the behaviour. I also tried extending the before NEW event of a rental to set the ID, which also did not resolve the issue sadly.

So i just decided to delete my custom service logic to just keep the generic event handlers, which still errors.

I exhausted all ideas me and my colleagues had, so id appreciate help 🙂

Dinu
Active Participant
0 Kudos

You write: When i edit a ressource and create a new rental in the rentals table on the object page.

How did you manage that? The association `rentals` is not a composition. So don't you need to create the rental entity in a separate draft session?

Accepted Solutions (1)

Accepted Solutions (1)

Dinu
Active Participant

According to documentation, only compositions should get `CREATE` button. If you are getting 'CREATE` button for rentals association, I suppose there is a bug in one (UI) or the other (CAP) framework. I don't think what you are trying to do from the UI is supported by default. Framework should have responded with a better message.

-- documentation --

Difference between Compositions and Associations

Be aware that all compositions of the draft enabled entity are part of the same draft. Only those entities will get a CREATE button in SAP Fiori elements UIs as they are part of the draft. Associated entities on the other side can only be deleted or modified. Note that, for associations the changes are directly applied instead of being applied once changes are saved to the active version.

Answers (1)

Answers (1)

eric_wu
Advisor
Advisor
0 Kudos

https://cap.cloud.sap/docs/cds/cdl#views-with-inferred-signatures

Could you kindly check this, seems the entity in service layer has no {*} to expose the key property.

Best regards,

Eric

Mathias-Storm
Discoverer
0 Kudos

Hey Eric,

thanks for your quick reply! The key property comes from the CUID aspect, its also visible in the frontend, so it should be accessible.

Or am i misunderstanding what you meant? What exactly should i check?

I appreciate your time, thanks!

eric_wu
Advisor
Advisor
0 Kudos

I mean please check this chapter in cap document https://cap.cloud.sap/docs/cds/cdl#views-with-inferred-signatures .

The key is aspcted by cuid, but this is in db layer, in your service layer, there is no property exposed explicity.