cancel
Showing results for 
Search instead for 
Did you mean: 

SAP Fiori validation before commit

tatiana_fetecua
Explorer
0 Kudos

Hi,

I have a fiori elements list report, and I want to validate data before doing the commit (I am using draft), I have found in the documentation that this could be done in a hook that was introduced in Feb 2022, req.before('commit'), I implemented this code but it is not working, does any one have an example or have used this before? did it worked? any other option to do a validation before saving the data (not when entering data)

based on the documentation it should be implemented like this:

srv.before('CREATE', Order, function(req) {

req.before('commit', async function() {

const { creditscore } = await SELECT.one.from(Customers)

.where({ ID: req.data.customer_ID })

if (creditscore < 42) throw new Error("We shouldn't make this sale")

})

})

but in my example it cannot find the before function property in the request (req.before), I also tried with the service, but it is not working either.

srv.before('COMMIT', Order, function(req) {}

Thanks,

Tatiana F.

View Entire Topic
Dinu
Contributor
0 Kudos

I would suggest that you reconsider your approach.

When the user saves data, that is what is commit from the User's perspective, data is copied from draft area to the active area. This is when your validations should run for best experience. The validation logic should be attached to SAVE event for this. SAVE is actually UPDATE or INSERT.

See sample code for doing this.