cancel
Showing results for 
Search instead for 
Did you mean: 

Capture error in PRECHECK method in SAP RAP

0 Kudos

Hello All,

I have implemented precheck during creation operation in the behavior definition, and want to achieve the following functionality:

1. While creating a new entry to a table, check if the entry is already present.

2. If present, give a error message mentioning "Entry already present, do you want to overwrite"?

3. If user still click on create after the error, then delete the old entry and create the new entry / or modify the existing entry.

I was able to achieve the functionality of step 1 and 2, but unable to figure out the way to capture the error, when user clicks on 'create' button again.

Is there any way that I can achieve this?

View Entire Topic
volkerdrees
Product and Topic Expert
Product and Topic Expert

This probably requires some UI coding.

The typical Fiori Elements UI orchestration sends a "Prefer: handling=strict" header with the first request. The backend precheck would raise a warning message (not an error and no failed key) in case of a conflict. This results in a http=412 precondition failed, which is recognized by the UI and a confirmation popup with the warning message is shown.

When you confirm this, a "Prefer: handling=lenient" header is sent and the processing continues.

Problem is, that your precheck implementation does not know about the http header sent by the client (which on the other hand is good, because in a stateless protocol you don't know if the first call has ever happened...). So the precheck will throw the warning again, which is then sent along with the http 200 response to the client. So you probably need some UI code on the client to suppress the second message.

Best Regards,
Volker

0 Kudos

Hi Volker,

Thanks for the information. We have implemented an alternate approach to achieve this functionality.

Regards,

Naga

p619793
Active Participant
0 Kudos

Thanks volker.drees for this detailed answer. It helped me overcome a different issue I was facing. In my case I accidentally forgot to remove the failed key when I converted the message I was reporting from 'error' to 'warning'. This caused the confirmation popup message dialog at draft activate action not appearing as the response code was 400 instead of 412. Then your comment helped me lead to the right direction. I removed the code for assigning the failed key and the confirmation dialog appeared as expected.

Best regards,

Sumit

ana_mrzv
Explorer
0 Kudos

Hi Sunkara Naga Rao
Could you please share the idea of your solution?

nagaraosunkara
Explorer

Hello Ana Morozova,

We were using one more additional primary key field as version, so that even though we have a same entry in the backend, we will keep the version number as different and save the values.

Ideal way of generating entries with same key combination, please use the concept of

External Numbering and Managed Early Numbering

Please have a look into this blog:

https://discoveringabap.com/2023/03/02/abap-restful-application-programming-24-external-numbering-an...

Regards,

Naga