on 2022 Oct 27 4:07 PM
Hi,
I have a cds entity
entity Object : managed {
key id : UUID ;
objectType : Association to mdm.ObjectType not null;
externalKey : String(200);
.
.
}
With OData I can delete an Object only by it's id:
DELETE /servicename/Object('4711')
I would like to delete an Object by its objectType and externalKey, which are together unique. I have a custom action for this:
Service definition:
action deleteObjectByObjectTypeAndExternalKey(objectType:String, externalKey:String);
Implementation:
const cds = require('@sap/cds')
module.exports = function (){
this.on('deleteObjectByObjectTypeAndExternalKey', async (req) => {
// Read the id by given objectType and externalKey
let ids = await cds.run (`SELECT ID FROM OBJECTI
WHERE OBJECTTYPE_ID = '${req.data.objectTypeId}' AND EXTERNALKEY = '${req.data.externalKey}'`);
if( ids.length > 0)
{ // Now delete by id
// => How can I call the generic cds Odata handler here ?
}
});
But I do not know how to call the generic OData DELETE handler with the id, after I have selected it from the DB. I would like to do all the generic work, for example delete depending composition entities, by the generic handler.
Can somebody help me here?
Thanks
You can use cds.connect.to (name, options?) ⇢ service and then use the normal cds-ql DELETE syntax.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
61 | |
11 | |
7 | |
7 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.