2024 Oct 28 3:04 PM - edited 2024 Oct 28 5:10 PM
Hello CAP and Typescript experts,
I have defined an draft-enabled entity with additional computed fields as follows:
entity BaseSystemTypes : managed {
@title: '{i18n>Paltr_SystemTypes_ID_label}'
key ID : types.SystemType;
@title: '{i18n>Paltr_Common_Name}'
@mandatory
techName : types.TechnicalName;
@title: '{i18n>Paltr_Common_title}'
@mandatory
title : types.Title;
@title: '{i18n>Paltr_Common_isUsable_label}'
isUsable : Boolean default true;
myComputedField: String = ('');
}
Within the service SystemTypes as projection on BaseSystemTypes, I let calculate the field myComputedField after READ:
srv.after('READ', SystemTypes, async (req) => {
if (!req) return;
...
req.forEach((singleEntity: any) => {
singleEntity.myComputedField = 'Test';
}
}
In the Fiori App, if I create a new draft instance or change one of the fields manually of an existing record, the draft cannot be saved because "Property myComputedField does not exist in myservice.SystemTypes". If I comment the singleEntity.myComputedField = 'Test', the changes on drafts are working.
If I check the database table BaseSystemTypes, I cannot find the calculated field and I can see the calculated field within the draft views and draft table regarding myService_BaseSystemTypes_drafts. This is correct as far as I know.
But getting an error during creation or updating a draft , is this a bug now inside the UI5 framework ? Or do I have to delete now the changes using the srv.on events for CREATE/UPDATE ? I assumed calculated fields are ignored during any updates.
Request clarification before answering.
In the cds model, a computed field looks like this:'
"foo": { "@Core.Computed": true, "value": { "val": "bar" } }
I'm not sure what you are trying to achieve but if you want to adapt the value of a computed field,
you'd need to manipulate the object properly: `<entity>.foo.value.val = 'YOUR VALUE'`
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @patricebender , by the setup I think @shf maybe refers to Calculated Elements
But I do agree that maybe what it needs to be considered is the use of a Virtual Element.
User | Count |
---|---|
53 | |
6 | |
6 | |
5 | |
5 | |
4 | |
4 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.