2025 May 07 5:15 PM - edited 2025 May 07 5:16 PM
I have a CAP CDS application with below entities
entity Order : managed {
key orderId: String(10);
orderItems: Composition of many OrderItem on orderItems.order = $self;
}
entity OrderItem: managed {
itemId: String(10);
quantity: Integer
}
My requirement is to check if an item is there in stock when an OrderItem is created. I wrote a logic as below
Note: I have create service cds
const cds = require("@sap/cds");
module.exports = cds.service.impl(async (srv) => {
const db = await cds.connect.to("db");
const { OrderItems } = srv.entities;
srv.after('CREATE', OrderItems, async (data,req) => {
console.log(data)
console.log(req)
})
});
But in my case it is not reaching the console statement. Is there any way to do capture the new OrderItem in the service.
Request clarification before answering.
In the case of deep create, the create handler for the parent (Order) entity has access to the associated item.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
30 | |
21 | |
16 | |
8 | |
7 | |
6 | |
5 | |
4 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.