cancel
Showing results for 
Search instead for 
Did you mean: 

Perform a delete when in draft mode and set delete = true when already created in SAP FIORI / CAP

ruben-gr
Discoverer

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

heiko_witteborg
Explorer
0 Kudos

Hi Ruben,

I'm not sure if you are describing a backend or UI problem. Could you add more details, e.g. the error (and the scenario when this is happening)? Are you using the latest cds version?

Best regards,

Heiko

Accepted Solutions (0)

Answers (0)