Skip to main content
Post a question

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Answered

SalesFormLetter_invoice post action

Like (0) ShareShare
ReportReport
Posted on 22 Feb 2021 23:30:08 by 55

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

  • Martin Dráb Profile Picture
    Martin Dráb 230,488 Most Valuable Professional on 30 Jul 2021 at 08:41:08
    RE: SalesFormLetter_invoice post action

    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?

  • Swetha K Desai Profile Picture
    Swetha K Desai 50 on 30 Jul 2021 at 03:48:36
    RE: SalesFormLetter_invoice post action

    Hello Martin,

    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

    Thanks,

    Swetha K Desai

  • Swetha K Desai Profile Picture
    Swetha K Desai 50 on 29 Jul 2021 at 23:51:55
    RE: SalesFormLetter_invoice post action

    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

  • Darrell Crews Profile Picture
    Darrell Crews 55 on 01 Mar 2021 at 20:53:11
    RE: SalesFormLetter_invoice post action

    Thank you

  • Darrell Crews Profile Picture
    Darrell Crews 55 on 01 Mar 2021 at 20:52:55
    RE: SalesFormLetter_invoice post action

    Thank you

  • Suggested answer
    Frank Bruemmer Profile Picture
    Frank Bruemmer 345 on 23 Feb 2021 at 14:09:02
    RE: SalesFormLetter_invoice post action

    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

  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 230,488 Most Valuable Professional on 23 Feb 2021 at 07:03:19
    RE: SalesFormLetter_invoice post action

    SalesInvoiceJournalPost.endPost() sounds like the right place for what you asked for.

  • AndrĂ© Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 291,791 Super User 2024 Season 2 on 23 Feb 2021 at 06:36:07
    RE: SalesFormLetter_invoice post action

    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?

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.

Helpful resources

Quick Links

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey Pt 2

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,791 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,488 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans
Loading started