cancel
Showing results for 
Search instead for 
Did you mean: 

CAP: Fail to create associated entity in Fiori Elements App

phidoe
Explorer
0 Kudos

Dear community,

I am new to CAP and try to set up a little learning project.

I have to 2 entities: Employees & Vacations associated to each other.

My schema looks like this:

namespace pd.praxissuite;

entity Vacations {

key ID : UUID;

startDate : Date; @mandatory

endDate : Date; @mandatory

employeeID: String;

employee : Association to Employees on employee.ID = $self.employeeID;

note : String;

}

entity Employees {

key ID : UUID;

firstName : String; @mandatory

lastName : String; @mandatory

vacations : Association to many Vacations on vacations.employeeID = $self.ID;

}

Corresponding service:

using pd.praxissuite as praxissuite from '../db/data-model';

service vacationplan {

entity Vacations as select from praxissuite.Vacations;

entity Employees as select from praxissuite.Employees;

}

annotate vacationplan.Employees @odata.draft.enabled;

annotate vacationplan.Vacations @odata.draft.enabled;

I created a Fiori Elements List Report using Fiori Tools with Employees as main entity, leading to an Object Page with a section listing all Vacations in a table.

I can create and save new Employee without error. When I try to create a new Vacation entity on the detail page it fails with following error in cds watch console:

Hope someone can help.

Thanks a lot in advance,

BR,

Philipp

View Entire Topic
js2
Product and Topic Expert
Product and Topic Expert
0 Kudos

Given you are enabling drafts I think you want to switch the association to Vacations in the Employee entity to a Composition. the back link can stay as an association to one (you don’t need the on-part). Try that first and give it another test

phidoe
Explorer
0 Kudos

Hi Jason,
thanks a lot for your super quick reply. This seems to save my sunday.

I changed the schema to use a composition and needed to delete the odata draft annotation for vacations in the service.

Now it is working as expected - but I don't fully understand why. Could you elaborate a little on your suggestion with the composition?

Is there any way to use CAP with FE without utilizing the draft capabilities?

Thank you so much,

Philipp

js2
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Philipp, FE V4 does require drafts for crud operations. I can’t explain the intricacies of compositions but they do allow for deep operations.