cancel
Showing results for 
Search instead for 
Did you mean: 

CAP Access Entity in DELETE event handler

spenceryang
Explorer
0 Kudos

I am trying to manager sub-entities with handlers. I use handlers on Insert/Upser events to operate in sub-entities. I will also need to handle Delete events. However, it seems i have no access to the deleted entity nor the id from the endpoint path in after event.

I do can get Cqn which is json format. Do i have to map to a HashMap and track all the way down to get an ID?

I am wondering how could i get that information from context. Thanks!

Accepted Solutions (1)

Accepted Solutions (1)

marcbecker
Contributor

You can use the CqnAnalyzer to extract ID values from the CqnDelete statement, when using CAP Java.

gregorw
Active Contributor
0 Kudos

Is this tool also available externally?

spenceryang
Explorer
0 Kudos

Thanks a lot, Marc. If i'd like to use it in After event, can I pass it through `context.setResult()`? it seems doing it will block the original delete behavior?

marcbecker
Contributor
0 Kudos

gregor.wolf: I updated the docs link, used an internal one by mistake.

spenceryang: I don't understand what you mean by passing it through context.setResult(). The CqnAnalyzer extracts ID values from the CqnDelete statement, which you can retrieve with context.getCqn() in an event handler. Setting a result in an Before or On event handler will skip CAPs default On event handler, which executes the deletion on the database.

spenceryang
Explorer
0 Kudos


|| Setting a result in an Before or On event handler will skip CAPs default On event handler, which executes the deletion on the database.

Great point to know.

What if i'd like to use the full deleted payload in @After event, where happens after delete event? I saw in another post that I'll have to somehow pass the entity from @Before event to request object. See: https://answers.sap.com/questions/13055368/cap-after-delete-event-handler-accessing-the-delet.html

marcbecker
Contributor
0 Kudos

Yes, in CAP Java you could read the entity in a Before event handler and store it in the EventContext object using the generic put/get methods with your own key. In an After event handler you can access that again.

Answers (0)