Hi all,
In the absence of further replies from the community I will summarize the solution that we reached ourselves, to the question I asked:
We are now using 3 events, 2 from codeunit 80 Sales-Post, and 1 from the Sales Header Record:
[EventSubscriber(ObjectType::Codeunit, Codeunit::"Sales-Post", OnBeforePostSalesDoc, '', false, false)]
//This subscriber of ours does the changes that we want to undo if an error
// happens in Microsofts part of the posting process
[EventSubscriber(ObjectType::Codeunit, Codeunit::"Sales-Post", OnAfterPostSalesDoc, '', false, false)]
//This does stuff that we need done after a succesful post - it does not get
// called after an error
[EventSubscriber(ObjectType::Table, Database::"Sales Header", OnSendToPostingOnAfterPost, '', false, false)]
//In our tenant this gets called after each posting attempt, succesful or
// unsuccesful. We check if the posting failed, and in that case we undo the changes
// done in the OnBefore… handler
It is not ideal at all.
If somebody has a better solution we are still interested.
So in summary:
- we were not succesful in starting a transaction that would roll back our changes after an error happens in Microsofts part of the code
- we found a useable event, but it has disadvantages
(1. it always runs in our posting setup, but possibly not in others, 2. we have to test if the posting failed, instead of the event itself informing us)
Best regards,
Wolter Kaper
Entocare CV