web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

AX 2009 - Reprinting Invoices using Print Management via batch.

(0) ShareShare
ReportReport
Posted on by 77

Hi,

We've had some modification work done by a VAR on our install of AX 2009 so that instances of SalesInvoice are sent out by email to the customer that the invoice is for through a modification to Print Management, which is working well.

Now, we need to be able to reprint some of those invoices in case there is an issue, such as for example the SMTP server not working, the wrong email address being stored etc.

The CustInvoiceJournal form has a menu item which almost does exactly what we need under Preview/Print > Use Print Management. However, this uses the local user's email client. I want to replicate the functionality of this button to run in batch instead of on the client.

The button has the following in the clicked method:

 

while (custInvoiceJourLocal)
{
args.record(custInvoiceJourLocal);

if (custInvoiceJourLocal.SalesId)
{

new MenuFunction(menuitemoutputstr(SalesInvoice), MenuItemType::Output).run(args); // Sales order invoice

}
else
new MenuFunction(menuitemoutputstr(FreeTextInvoice), MenuItemType::Output).run(args); // Free text invoice

if (! journalList.next(custInvoiceJourLocal))
break;
}

super();

 

Presumably I have to alter the two lines in bold in some way so that the report is generated in batch rather than just instigated locally.

Please could someone give me some guidance on how to proceed?

*This post is locked for comments

I have the same question (0)
  • Community Member Profile Picture
    on at

     let me know your class, you have to extend your class with runbasebatch class.   

  • PhilMatthews Profile Picture
    77 on at

    Hi Kumkum,

    I haven't written a class yet as I'm not familiar with writing classes to run in batch.

    So do I create a new class which extends RunBaseBatch and make it run the code highlighted in bold, or is there a lot more to it than that?

    Thanks in advance.

  • Community Member Profile Picture
    on at

    yes, example which you are referring (CustInvoiceJournal ) is running on client. if you want to run  your functionality on batch  , you need to write Batch class having your functionality at place.

    please use below link to write batch class.

    axaptapiyush.blogspot.com/.../creating-batch-class-in-dynamics-ax-2009.html

  • PhilMatthews Profile Picture
    77 on at

    I have followed the example, but I'm missing the point somewhere. The batch class that I've written sends the job to batch, but Errors with nothing in the log. Is there anything obvious that I've done wrong?

    class TTN_SalesInvoiceJournalReprintBatch Extends RunBaseBatch

    {

      CustInvoiceJour     custInvoiceJourLocal;

    }

    void initFromArgs(Args  _args)

    {

       ;

       if (_args.record())

       {

           custInvoiceJourLocal = _args.record();

       }

       else{

           error("No record passed.");

       }

    }

    public container pack()

    {

       return connull();

    }

    public boolean unpack(container packedClass)

    {

       return true;

    }

    server static TTN_SalesInvoiceJournalReprintBatch construct()

    {

       return new TTN_SalesInvoiceJournalReprintBatch();

    }

    static void main(Args args)

    {

       TTN_SalesInvoiceJournalReprintBatch    JournalReprintBatch;

       ;

       JournalReprintBatch = TTN_SalesInvoiceJournalReprintBatch::construct();

       if (JournalReprintBatch.prompt())

           JournalReprintBatch.run();

    }

    public void run()

    {

       ReportRun               reportRun;

       Args                    reportArgs = new Args(reportstr('SalesInvoice'));

       try

       {

           reportArgs.record(custinvoiceJourLocal);

           reportRun = new ReportRun(reportArgs);

           reportRun.init();

           reportRun.run();

       }

       catch

       {

           throw Exception::Error;

       }

    }

    And instigated thus:

    journalList.first(custInvoiceJourLocal);

       while (custInvoiceJourLocal)

       {

           myArgs = new Args();

           menuFunction = new Menufunction(identifierstr(TTN_SalesInvoiceJournalReprintBatch), MenuItemType::Action);

           myArgs.record(custInvoiceJourLocal);

           menuFunction.run();

           if (! journalList.next(custInvoiceJourLocal))

               break;

       }

    Any suggestions would be appreciated.

  • Community Member Profile Picture
    on at

    are you passing any parameters ?  please check Pack & unpack methods, put debugger and see if you are passing values in pack and unpack methods .  

  • PhilMatthews Profile Picture
    77 on at

    I've moved forward slightly now. The report is generated in the class and the Batch Job completes successfully. However, the generated document then seems to disappear! The email is never sent. No record of it on our SMTP server, nor under Administration > Periodic > Email Processing > E-mail Sending Status.

    I've confirmed using debugging that the print management destination is set to email and that the email "To" field is populated. I do not know where to begin the next stage of debugging the issue. What has happened to this email?

    Thanks in advance.

  • Community Member Profile Picture
    on at

    are you getting any batch LOG ? I can not see your code, I am on Ax2012 R2, but I would say you are very close , check if you have permission to send data on SMTP server .

    During Debugging can you see if your Code is creating Record ?

  • PhilMatthews Profile Picture
    77 on at

    The batch job appears in the batch job list and completes, but does not leave any log information at all. 

     

    I definitely have permission to send on the SMTP server as when I create a full invoice run under Sales Ledger > Periodic > Sales Update > Invoice, it generates the invoices and sends them out via email.

     

     

  • Community Member Profile Picture
    on at

    it happens when batch is not able to pack & unpack values, do you have list of parameters & list Version..  

  • PhilMatthews Profile Picture
    77 on at

    Hi Kumkum,

    Assuming that I am understanding the usage correctly, yes.

    In the classDeclaration of my batch class, I have declared thus:

      #define.CurrentVersion(1)

         #define.Version1(1)

         #localmacro.CurrentList

           custInvoiceJourLocal

      [tag:endmacro]

    Then unpack:

    public boolean unpack(container packedClass)

    {

       Version version = RunBase::getVersion(packedClass);

       ;

       switch (version)

       {

           case #CurrentVersion:

               [version,#CurrentList] = packedClass;

               break;

           default:

               return false;

       }

       return true;

    }

    and pack:

    public container pack()

    {

       ;

       return [#CurrentVersion,#CurrentList];

    }

    The correct value is passed in custInvoiceJourLocal, because I have outputted it to the infoLog which is recorded against the batch job.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans