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

Difference between events 'CREATE' , 'INSERT' custom handlers CAP Node.js

Ramjee_korada
Active Contributor
0 Likes
881

Hello Experts,
Can you please help me with the difference between the events CREATE and INSERT? When should I use each one, and what is the best practice? Also, what is the standard sequence of invocation? Based on my debugging, it appears that whichever event handler is implemented first is the one invoked first.

this.before('CREATE', Properties, async (req) => {
}

this.before('INSERT', Properties, async (req) => {
}

Best regards,
Ramjee Korada

 

Accepted Solutions (0)

Answers (2)

Answers (2)

ESWAR_NEKKALAPU9
Explorer
0 Likes

Hi Ramjee,

You can check the official CAP documentation here:
👉 https://cap.cloud.sap/docs/node.js/events

The docs explain the different event types such as CREATE, READ, UPDATE, DELETE, and custom events. However, CAP does not guarantee a fixed order of execution when multiple handlers (like CREATE and INSERT) are implemented for the same entity.

From practical experience, CREATE is the higher-level event that wraps the insert logic, and the order of execution you see is often due to how the handlers are registered in code, not a defined framework rule.

So the best practice is to use CREATE for general logic and reserve INSERT only for database-level customization.

Ramjee_korada
Active Contributor
0 Likes

Hi Eswar,

thanks for revised answer - I also went through this documentation already. 
As you noticed, there was no mention of 'INSERT' in the documentation and there is no guarantee of the sequence of execution. 

Best regards,
Ramjee Korada

ESWAR_NEKKALAPU9
Explorer
0 Likes

In CAP, CREATE is the generic event that covers both INSERT and UPSERT operations. When you create a record through standard CAP APIs (for example using POST /entity), the framework triggers the CREATE event first.

INSERT is more specific and is only triggered when the operation is explicitly an insert into the database.

So in sequence, if both are implemented, CREATE runs before INSERT.
Use CREATE when you want logic to run for all create-type operations, and INSERT when you need something to happen only during a pure insert to the database table.

In practice, most developers use CREATE for validation or preprocessing and reserve INSERT for low-level data manipulation before persistence.

Ramjee_korada
Active Contributor
0 Likes
thank you for your reply - Can you please share the reference from capire documentation?
Ramjee_korada
Active Contributor
0 Likes
thank you for your reply - Can you please share the reference from capire documentation? as mentioned , it appears that whichever event handler is implemented first is the one invoked first.