Hi everybody.
It seems there is a BIG Design flaw on the very basic level in Business Central Architecture if Im right in the following.
The scenario goes as
1) External system invokes Codeunit webservice in Business Central (latest version)
2) CodeUnit webService stores the Payload in a table with status "Received" and Commits
3) Codeunit webservice executes the business logic (inserting, modifying records) in a new transaction
4) Step 3) fails in some way (The business logic is only using collectible errors).
5) If any collectible errors have been found - ROLLBACK all database updates done in 3)
6) Save all collected errors in a record.
This is a pretty basic way of creating webservices in every other programming language that Im using. Somehow this simple pattern does not seem to be possible in BC ??
When saving all the collected errors in 6) business central is also saving all intermediate database record inserts/modified as part of 3)
But I want to rollback those and simply store the error messages.
If this it not possible I would rather say that BC is not mature in any way hence lots of business central instances must have weird/not complete data stored?
I must be missing something here - so any help is appreciated.....
BR Morten
UPDATE 16/01/2025
What Alexander is mentioning below is correct and the standard way of executing logic in an independent transaction.
This pattern was followed in my code BUT as part of my code I was calling the procedure "SendToPosting" on the SalesHeader table.
Thats DANGEROUS because inside this method an explicit COMMIT is executed, forcing the surrounding transaction to be comitted.
That was the culprit.