Hello Dynamics Community,
I need to run some code after posting a sales order invoice. I tried creating various post event handlers as well as a chain of command approach, but for some reason, my code is never executed. It appears that since this is executed as a service things are different. Can anyone elaborate ? What is the right way to run code after let's say salesFormLetter_Invoice.update() ?
Sincerely
Darrell
Hi Darell,
Usually CoC would be an option, but you made this attempt already. Can you share your code and tell what exact business requirement you try to fulfill?
SalesInvoiceJournalPost.endPost() sounds like the right place for what you asked for.
Hey Darrell,
as Martin suggested, this approach will work :
[ExtensionOf(ClassStr(SalesInvoiceJournalPost))]
final class SalesInvoiceJournalPost_Extension
{
protected void endPost()
next endPost();
Info(strFmt("SalesId : %1",custInvoicejour.salesId));
}
I don't think you will be able to use pre/post event handlers as endPost() is not a public method (protected).
Best regards
Frank
Thank you
Hello Martin,
I have a post event handler method written on the SalesFormLetter_Invoice - run method. In this post event handler, there is custom code to post the amortizations (revenue recognition entries) on the invoice.
When I post an invoice manually, the post event handler does get fired and the amortizations do get posted. However, when this is done through a batch job, the amortizations are NOT posted as the post event handler does not seem to execute.
When I try to debug this in batch mode, I am unable to hit the breakpoint and the batch job finishes with invoice posting correctly with no amortizations posted. I understand that this behaviour might be because the batch job is multithreaded.
Can you please suggest where the code can be rewritten so this can be executed in batch mode as well. Does SalesInvoiceJournalPost.endPost() still would help? Also, any pointers you can give me to help debug multithreaded batch jobs?
Thanks,
Swetha K Desai
The wrote the code in the custom code in SalesInvoiceJournalPost.endPost() , although manual posting behaviour did not change, the batch posting still does not post amortizations.
Will check more on the batch posting in LedgerJournalCheckPost class and update if any progress
LedgerJournalCheckPost is used in batch posting as well. What exact problem do you have with debugging?
Can you show us your code, please? Did you see the verified answer above which uses Chain of command?
Under review
Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.
As AI tools become more common, we’re introducing a Responsible AI Use…
We are honored to recognize Pallavi Phade as our Community Spotlight honoree for…
These are the community rock stars!
Stay up to date on forum activity by subscribing.
André Arnaud de Cal... 686 Super User 2025 Season 2
Martin Dráb 585 Most Valuable Professional
CA Neeraj Kumar 565