Skip to main content

Notifications

Microsoft Dynamics AX forum
Answered

Run method after Generating Sales Invoice

Posted on by Microsoft Employee

Sales order Lines > Invoice > Generate (Invoice) > PrintMgnmt > OK

i need to run a method after Generating Sales Invoice

I tried putting the code in the last part or closeOK and closedOK (i tried info("aa"); first)

but when i tried it, it will prompt before the Confirmation Warning ("Warning: You are posting the invoice and printing to screen only.").

how can i put it after the Warning and everything is OK and POSTED.

please help. thanks.

Categories:
  • Verified answer
    Brandon Wiese Profile Picture
    Brandon Wiese 17,786 on at
    RE: Run method after Generating Sales Invoice

    I've also had forms that need to appear after some form letter document is posted, such as the Sales invoice.

    Try launching your form in the SalesFormLetter_Invoice class in the run() method after the super() call.  Make sure NOT to launch your form when it's not appropriate.  For example, if the Sales invoice is proforma, then there will be no records left, so probably not useful to launch your form.  If the thread is a CLR session, then you won't be able to run client code at all and it will error if you try.

    Here's a sample of code that I've actually used for this purpose.  In my case I only wanted the form to appear if the form letter document wasn't printed, hence the !this.printFormLetter() check.

    super();

    if (!this.salesParmUpdate().Proforma && !this.printFormLetter() && this.parmShowDialog()) { if (xGlobal::hasClient() && !xSession::isCLRSession()) { // launch your form here } }
  • sohaibcheema Profile Picture
    sohaibcheema 46,594 User Group Leader on at
    RE: Run method after Generating Sales Invoice

    a good approach can be to follow the path of sales invoice report, i.e. as you are going to post an invoice there is checkbox, if you check it,, it prints sales invoice report, else it ignores it. in case you marked this checkbox of printing invoice, it is printed only in case, invoice has no issues and everything is fine. i.e after posting the invoice the printout appears.

    so do follow the same logic and let your custom form appear somewhere before or after that report because till that moment,, invoice is already posted (either in case of Performa or actual posting)

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Run method after Generating Sales Invoice

    Hi martin,

    im supposed to run a custom form that su,mmarizes and splits the sales invoice by 15 lines each, and giving them each a preprinted si number for printing. I msnaged to make it and it is working now (tested it All in custom tables/forms to run).

    But now i need to deploy it in the SI posting now, which is the problem, i need posted SI before running the custom form.

    How can i run it after posting SI(after all the warnings yes/no)

  • Suggested answer
    Martin Dráb Profile Picture
    Martin Dráb 227,996 Super User 2024 Season 2 on at
    RE: Run method after Generating Sales Invoice

    Posting is done in SalesInvoiceJournalPost class. You can find it by yourself next time in Using the Refactored Formletter Framework.

    I can't say what would be the place for your business logic because you didn't tell us anything about it.

Helpful resources

Quick Links

Dynamics 365 Community Update – Sep 9th

Welcome to the next edition of the Community Platform Update. This is a weekly…

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,186 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 227,996 Super User 2024 Season 2

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans