cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Custom Logic in CREATE handler of composition items : SAP CAP

0 Kudos
106

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.

 

 

Accepted Solutions (0)

Answers (1)

Answers (1)

MioYasutake
Active Contributor
0 Kudos

@akhthaaralibadhusha 

In the case of deep create, the create handler for the parent (Order) entity has access to the associated item.