on ‎2020 Sep 25 10:22 AM
Hallo Experts, I have an issue about READ handler.
I have an Entity with calculation fields. In order to set these fields, I have implemented READ handler.

Triggering a GET request everythings is ok: fields are calculated.

Triggering a PUT request in order to modify entity’s data, fields are empty.


CAP after update runs _readAfterWrite function; this function re-loads entity’s data from DB correctly. After this function, CAP should trigger my READ handler, but it doesn’t.
As a result my calculated fields are empty.

Any ideas on how to solve this problem?
Best regards.
Alice
Help others by sharing your knowledge.
AnswerRequest clarification before answering.
Thank you Sebastian Van Syckel,
the right answer is:
/*
* srv/raw-service.js
*/
const cds = require('@sap/cds')
module.exports = async function() {
const { ReadAfterWrite } = this.entities //> ReadAfterWriteService.ReadAfterWrite
const DatabaseService = await cds.connect.to('db')
// register for ReadAfterWriteService.ReadAfterWrite as this is the target of the SELECT query
DatabaseService.after('each', ReadAfterWrite, (row) => { //> invoked for each row of a READ result
row.text2 = 'virtual text'
})
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 12 | |
| 9 | |
| 6 | |
| 4 | |
| 4 | |
| 4 | |
| 3 | |
| 3 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.