Search code examples
sapui5cds

Validate user input via CDS annotation?


I'm new to SAP, UI5 and CDS annotations. I've created a CDS view and created the application using Web IDE Template project, list report template. The application works fine, but I want to add following validations

In my CDS I’m having a quantity field. I want to have a greater than zero value when user saving records through the List report application. Can I do it using UI5 annotations?

And In the CDS I have defined 2 key fields. In the application when trying to create duplicate record application navigates to an error page indicating error occurred. How can I validate duplicate records based on the key fields and give warning or error to customer when creating a new record?

Thanks in advance


Solution

  • To anyone who is trying to do validations using annotations, I did not find a way to do the validations using annotations, in a consumption view when writing data.

    I the only way I found to validate the inputs is to write the validation logic in the BOPF object crated when activating the CDS. But that will be in ABAP code and you need the basic ABAP knowledge.