There was a requirement to archive the Sales Order document when it is completely invoiced and before the deletion.
So I looked into Codeunit 80 which is Sales-Post and Codeunit 5063 which is ArchiveManagement to inspect how the standard archiving/deleting get performed.
It is evident that every time the Sales document is shipped, the document will be archived with versioning upon the Sales & Receivables Setup.
So I called the standard archiving function which is on the Codeunit 5063, on to Table 36 which is Sales Header, on OnDelete() trigger. I was assuming that after completely invoiced, Sales-Post Codeunit will call OnDelete() trigger in order to delete the document.

But I was wrong since it does not call the OnDelete(), and deletes the document right after deleting. As seen on image 1a, the system does not call OnDelete(). This perfectly makes sense because the system surely knows that it has completely invoiced the document, hence no need to trigger OnDelete().
But I called OnDelete() of Sales Header table just to check what is the implication. It throws an error from the Sales Line table.
So I had to place the archiving code before the DELETE; code on Sales-Post, so it worked perfectly.


Like
Report
*This post is locked for comments