on ‎2025 Nov 06 9:47 PM
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
Request clarification before answering.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 8 | |
| 5 | |
| 4 | |
| 4 | |
| 3 | |
| 3 | |
| 2 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.