on 06-05-2023 11:56 PM
Hello CAP Team,
I want to create an action to perform a delete when in draft mode and set delete = true when already created. When is in draft mode, it deletes correctly but not refreshing the table list and when is already saved it gives an error.
Service .cds file:
@Capabilities.Deletable: false<br> entity BrandCars as projection on Brands_per_Cars <br> actions {<br> @cds.odata.bindingparameter.name: 'in'<br> @Common.SideEffects #logicalDeletion: {<br> TargetEntities: ['in/cars/brands']<br> }<br> action logicalDeletion() returns BrandCars;<br> }
js:
srv.on('logicalDeletion', 'BrandCars', async (req) => {<br>await oProgramHandler.onLogicalDeletion(req) })
handler:
onLogicalDeletion = async (req) => {
for(let index = 1; index < req.params.length; index ++) { const aDraft = await SELECT.from('CARS_BRANDSCARS_DRAFTS').where({ID: req.params[index].ID})
if(Boolean(aDraft[0].HASACTIVEENTITY) === true) {
await UPDATE('CARS_BRANDSCARS_DRAFTS', req.params[index].ID).set({DELETED: true, DELETEDAT: req.timestamp, DELETEDBY: req.usr.id})
} else {
await DELETE('CARS_BRANDSCARS_DRAFTS').where({ID: req.params[index].ID})
}
}
frontend (FIORI):
<Annotations Target="cars.logicalDeletion(cars.BrandCars)"> <Annotation Term="Common.SideEffects" Qualifier="logicalDeletion"> <Record Type="Common.SideEffectsType"> <PropertyValue Property="TargetEntities"> <Collection> <NavigationPropertyPath>in/cars/brands</NavigationPropertyPath> </Collection> </PropertyValue> </Record> </Annotation> </Annotations>
Best Regards,
Ruben Rodrigues
User | Count |
---|---|
77 | |
9 | |
9 | |
7 | |
7 | |
6 | |
6 | |
6 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.