on ‎2021 Aug 05 3:01 PM
Hi experts!
In my project I am displaying a table with columns for the start time, end time and duration of an event. I would like to connect these so that if the user enters a start time and an end time, the duration is automatically calculated and entered for them while still in edit mode. Illustrations below:


The backend consists of a SAP CAP odata v4 service, and as such I was thinking maybe I could intercept the PATCH request sent when the user finishes entering the EndTime (srv.before('PATCH',...) {...}) and modify the provided data. This works and changes the model. But it does not refresh the Objectpage when completed, and thus any changes only appear after the page has been reloaded. Any help as to how to achieve this in Fiori Elements would be much appreciated!
Best regards,
Jibbril
Request clarification before answering.
Hi Jibbril,
maybe the Annotation SideEffects can help you. I have an example in srv/admin-service.cds#L100.
CU
Gregor
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Gregor Wolf provided the correct answer in the form of Side Effects. Below is an example implementation for anyone who might be facing similar issues.
// schema.cds
entity MyEntity {
StartTime: Time;
EndTime: Time;
Duration: Decimal;
}
// my-service.cds
service MyService {
@Common.SideEffects #EndTimeChanged : {
SourceProperties: [ EndTime ],
TargetProperties: [ Duration ]
}
entity MyEntity as projection on db.MyEntity;
}
// my-service.js
srv.before('PATCH', 'MyEntity', req => {
// Check if EndTime is changed in the PATCH request
if (req.data.EndTime) {
// If it is, add appropriate Duration change to request data
req.data.Duration = getCorrectDuration(req.data.EndTime);
}
});Best Regards,
Jibbril
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 8 | |
| 5 | |
| 4 | |
| 4 | |
| 3 | |
| 3 | |
| 2 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.