cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Simultaneous update when editing table in Fiori Elements

1,599

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

Accepted Solutions (1)

Accepted Solutions (1)

gregorw
SAP Mentor
SAP Mentor

Hi Jibbril,

maybe the Annotation SideEffects can help you. I have an example in srv/admin-service.cds#L100.

CU
Gregor

0 Likes

Hello Gregor,

This worked brilliantly, thanks for the help!

Best Regards,

Jibbril

Answers (1)

Answers (1)

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