cancel
Showing results for 
Search instead for 
Did you mean: 

srv.before('PATCH, 'entity',...) not being triggered

protector
Discoverer
0 Kudos

Hello CAP team,

I am attempting to capture a PATCH request within a CAP service that is triggered when fields are changed in a draft mode creation form of an entity. However, I am unable to detect any logs indicating that the PATCH handler has been triggered.

From my service cds file:

@odata.draft.enabled
entity Materials as projection on WNBGReferencesApp.Materials

Output example in console:

[odata] - POST /service/WNBGReferencesApp/$batch 
[odata] - > PATCH Materials(ID=8c8e8a5a-6475-4094-9916-d8eeff98cf32,IsActiveEntity=false)
[odata] - > READ References(ID=e3ff58e7-4e59-4fa1-b258-93e287419560,IsActiveEntity=false)/materials(ID=8c8e8a5a-6475-4094-9916-d8eeff98cf32,IsActiveEntity=false)

PATCH handler:

this.before('PATCH', 'Materials', async(req) => { console.log("Material PATCH IS TRIGGERED") });

I am not sure what I am missing. (I am a beginner)

Cguttikonda
Explorer

Hello,

Patch is considered as UPDATE event, so change the event to Update and try.

Accepted Solutions (1)

Accepted Solutions (1)

Dinu
Active Participant
0 Kudos

With lean draft, handlers for PATCH requests to drafts need to be attached to UPDATE of the draft entity. This would be this.entities.Materials.draft in your case.

See documentation.

protector
Discoverer
0 Kudos

Thank you the prompt reply.

Could you please elaborate a little more on that?

Dinu
Active Participant
0 Kudos

change to:

this.before('UPDATE', 'Materials.drafts', async(req) => { console.log("Material PATCH IS TRIGGERED") });
protector
Discoverer
0 Kudos

A legend, thank you much!

Answers (0)