Unified Operations & Dynamics AX Forum

Expand all | Collapse all

Batch invoice - Random missing info logs for print / email

  • 1.  Batch invoice - Random missing info logs for print / email

    SILVER CONTRIBUTOR
    Posted 04-19-2017 12:20 PM
    Edited by Rich Krol 04-19-2017 01:03 PM

    We are starting to batch invoice daily, and have anywhere from 200-300 invoices that post.  We have gone through test, and have had great success, with the number of postings that should happen.

    We are using Print Management, so we can utilize email for most customers, and have about 1/4 customers that request a hard copy printed and stamp mailed to them. 

    The Log for the batch job we have export to Excel, so we can review daily, until we are satisfied for the next few weeks on what we see going through the system.  We have a current  situation, where there will be no info log record for a Sales Orders' printing, on it's successful or failed attempt to print/email using print management.  That worries us, on if the customer was emailed successfully (or a printout) so they know they have an invoice pending.

    Here is what a snippet of the log looks like, when a successful post and email occurs for 99% of our orders, and you can see about mid way, that there is no info log for order SO-6, on it's success/fail through print management.  It's a non-sample, non $0.00 order, where and invoice should go for all purposes.  Has email setup in print management, can email customer otherwise successfully from previous invoice postings through batch, and from outlook client.

     

    SO-6 is the sales order example in question.

     

    (For info security purposes, I renamed emails, printer, PO, and sales order items for this post)

     

    Order ID: SO-1

    Report SalesInvoice.Report was sent to printer \\server.network.net\printer123 (Invoices).

    Order ID: SO-2

    The report has been successfully sent as attachment to email.  to-email1@emailcustomer.com subj-Sales Invoice for Purchase Order 333444

    Order ID: SO-3

    The report has been successfully sent as attachment to email.  to-email444@emailcustomer.com subj-Sales Invoice for Purchase Order 4444455555

    Order ID: SO-4

    The report has been successfully sent as attachment to email.  to-email678@emailcustomer.com subj-Sales Invoice for Purchase Order 433463456

    Order ID: SO-5

    The report has been successfully sent as attachment to email.  to-email333333@emailcustomer.com subj-Sales Invoice for Purchase Order 999999999

    Order ID: SO-6

    Order ID: SO-7

    The report has been successfully sent as attachment to email.  to-email14747@emailcustomer.com subj-Sales Invoice for Purchase Order 07658757685

    Order ID: SO-8

    Report SalesInvoice.Report was sent to printer \\server.network.net\printer123 (Invoices).

    Order ID: SO-9

    Report SalesInvoice.Report was sent to printer \\server.network.net\printer123 (Invoices).

    Order ID: SO-10

    The report has been successfully sent as attachment to email.  to-email17777@emailcustomer.com subj-Sales Invoice for Purchase Order 12343456568

    Order ID: SO-11

    Report SalesInvoice.Report was sent to printer \\server.network.net\printer123 (Invoices).

     

    We have spent a few days researching this, looking through code, any modifications…. Can't seem to pinpoint anything about the order or the customer setup, that would prevent an email from attempting to be sent, or why the info log won't have a record that this was attempted.  And in fact, when refreshing our test system for another test round, different random (1%) of customer won't get emailed, and the customers invoice on the next test, would run successfully…. Very weird… no repeatable pattern.

     

    Only input I have received so far, is changing our Print from "Current" to "After", which would print all of the invoices to print management "After" all the posting for all orders is completed.  Not sure what is preferred, but If anyone has input, seen this before, or have insight on how to troubleshoot this "random-ness", I'd be all ears.

     

    AX 2012 R3 CU8



    ------------------------------
    Rich Krol
    IT Business Analyst
    Applied Medical Technologies, Inc.
    Brecksville OH
    ------------------------------


  • 2.  RE: Batch invoice - Random missing info logs for print / email

    TOP CONTRIBUTOR
    Posted 04-19-2017 01:11 PM
    Hi Rich,
    There's another thread going that is extremely similar to your issue right now.  The other user is not doing batch processing but it sounds like the exact same issue otherwise.  I was actually going to suggest to that user that he try doing batch to see if that throws any helpful errors.  Your issue would suggest it won't.  Here's the other thread.
    Open Forum - AXUG - Dynamics AX User Group
    Axug remove preview
    Open Forum - AXUG - Dynamics AX User Group
    Hidden page that shows all messages in a thread
    View this on Axug >


    ------------------------------
    Jessie Swartz
    Senior Functional Consultant
    Stoneridge Software Inc.
    Minneapolis, MN
    ------------------------------



  • 3.  RE: Batch invoice - Random missing info logs for print / email

    SILVER CONTRIBUTOR
    Posted 04-19-2017 02:42 PM
    Thanks Jessie!  I reviewed the article and commented for the post.

    We are continuing to look here, and will update if I find anything, but nothing yet seems to stand out.

    Thanks!

    ------------------------------
    Rich Krol
    IT Business Analyst
    Applied Medical Technologies, Inc.
    Brecksville OH
    ------------------------------



  • 4.  RE: Batch invoice - Random missing info logs for print / email

    GOLD CONTRIBUTOR
    Posted 04-19-2017 04:15 PM
    Rich, if you know the email addresses for the invoices that did not get logged as successfully emailed for a specific invoicing run, give that list of email addresses to your Network Administrator to confirm whether or not an attempt was even made to email the invoices.

    In regards to why those invoices didn't print in addition to not getting emailed, is it possible that the invoices are being generated too quickly for the print and email servers to keep up, and some invoices are getting "lost" because the servers are being bombarded by too many invoices to print and email at the same time?  This was an issue that we had in our previous ERP, and I resolved that by putting in a 2 or 3-second delay in between invoices.  (I implemented a 5-second delay in AX in an attempt to resolve an emailing issue where 6 - 10 invoices would fail to email every night for no apparent reason.)

    Perhaps you could try to force a 2 - 3 second pause between invoices too.  Just be aware that the invoicing batch job would take 10 - 15 minutes longer to run for the 300 invoices that you typically generate during a batch invoicing run.

    ------------------------------
    Rudy Salcedo
    Senior Programmer/Analyst
    LaForce, Inc
    Green Bay WI
    ------------------------------



  • 5.  RE: Batch invoice - Random missing info logs for print / email

    SILVER CONTRIBUTOR
    Posted 04-19-2017 04:46 PM
    Hi Rudy!  Thanks for the reply.

    Our network admin validated today's emails, and the SMTP logs showed they were queued for delivery, and were sent.  From what I can tell, AX will just create a info record in the log, commenting on the fact that it went out, and that's the part where we'd need to have a "wait" period so the logs can catch up.

    Talking with our Dev, that's something that he can make happen, by placing in a timer for such a thing.  We will discuss this in the next day, and run past our management, to see if it's a viable solution, or at least we can put in test to see if we have better results in the log.

    Not a "thrilling" resolution, but won't complain too much if it works.

    Thanks!

    ------------------------------
    Rich Krol
    IT Business Analyst
    Applied Medical Technologies, Inc.
    Brecksville OH
    ------------------------------



  • 6.  RE: Batch invoice - Random missing info logs for print / email

    GOLD CONTRIBUTOR
    Posted 04-19-2017 05:27 PM
    Rich, in case it helps, here's a snippet of some code that I added to the runPrintMgmt method of the SalesInvoiceController class.


    The 5-second delay didn't actually resolve the emailing issue I mentioned previously, so I'll eventually remove it.

    The info message was added because AR had no way to determine which invoice was printed or emailed.  We're on AX 2012 R2 CU7, and the invoicing infolog previously only indicated that an invoice was either successfully printed or emailed.

    I put the this.outputReports() statement in a Try-Catch block to prevent the batch job from erroring-out when an error was encountered during printing or emailing.



    ------------------------------
    Rudy Salcedo
    Senior Programmer/Analyst
    LaForce, Inc
    Green Bay WI
    ------------------------------



  • 7.  RE: Batch invoice - Random missing info logs for print / email

    SILVER CONTRIBUTOR
    Posted 04-20-2017 09:37 AM
    Rudy, thanks again!

    We are going to try the sleep, but start low.  We are thinking even a 1/2 a second would help in our instance.  Something worth trying, and then move on from there.  We are not excited about prolonging our invoice process.  We typically would like to have all invoicing done by end of business day, rather than overnight invoicing, or going past 5 PM EST.  I'll be able to run a test today, in our TEST systems, for 230+ orders.

    The other code snippets you have are great!  We currently just match whats in some created filters in our Sales Order screens, and go off a few reports for "Order Lines Not Invoice" so we have a great system now after the batch runs to "double-check" our work.  We'll keep the info write line you created in mind, if we want that on our daily report, that we create from the info log.

    We haven't' gotten any errors (yet) on printing of emailing through PM, but the try-catch makes a lot of sense.

    Will keep posting on what I find, or what we resolve.

    ------------------------------
    Rich Krol
    IT Business Analyst
    Applied Medical Technologies, Inc.
    Brecksville OH
    ------------------------------



  • 8.  RE: Batch invoice - Random missing info logs for print / email

    SILVER CONTRIBUTOR
    Posted 04-20-2017 03:12 PM
    So we ran two test instances, same set of sales data for invoicing (basically refreshed out test system data) and no change.  We did a sleep for 1 second.

    Each instance had different orders posted, without an info log on the print management.  They were not the same orders on the second instance.  One customer was set default to printer, one set default to email.  Nether output was generated.  (We use PaperCut from CodePlex to receive SMTP traffic from test, and default print).

    So sometimes, it will hard-print or send SMTP and not report info.
    Other times, it will NOT hard-print or send SMTP and not report info.

    Print Management must not be "finishing" something... in layman's terms.

    Will try and do some hotfix searching on LCS/CS, and escalate to Microsoft from there.  I can't have the "looseness" of an infolog, when I need to record output on something important as an Invoice.  And, I don't want to manually every day (or have a user) check breaks in the info log, then ask IT admins to daily check SMTP logs.  OK sure, it's like 1-3% of invoices, but I can't risk customers not getting invoices. sorry... venting at this point.  :-P

    Will continue my search, and report back to the users here, you peeps have been great so far!

    ------------------------------
    Rich Krol
    IT Business Analyst
    Applied Medical Technologies, Inc.
    Brecksville OH
    ------------------------------



  • 9.  RE: Batch invoice - Random missing info logs for print / email

    SILVER CONTRIBUTOR
    Posted 09-26-2017 10:33 AM

    Being a good AXUG peep, and posting a resolution, although this is an older post I initially created.

    So we figured out the issue with some invoices not getting emailed, without any notification in the Info Logs.  Keep in mind, we do have some modifications to our print management, but a lot of what I have described below is native AX processes.

    When running in a batch, AX makes use of the service account you have setup in AX.  In a lot of cases, yours may be something like "AXPROXY" or "BusConProxy", depending on your initial setup of AX or if a VAR did it for you. 

    When the batch jobs run, it uses the temp folder of the users account in /%USERNAME%/AppData/Local/Temp to create a .tmp file (ex. TmpAC4F.tmp) of the invoice after it posts.

    Then, the batch job transfers it to a folder with the same name of the .tmp file (ex. TmpAC4F).  It then renames that .tmp file SalesInvoice.pdf after it's in that folder.  From here, the batch job sends it off to your SMTP server you have setup in email settings.

    ISSUE:

    The issue, is that AX is generating a random 4-digit hex number, for the name of the .tmp file (ex. TmpAC4F.tmp).  This allows only about 64,000 different naming possibilities.   Eventually over time, if you are running invoices through a batch, the folder will fill up (in our case about 40,000 temp folders with a hex name).  So AX was generating duplicate files names randomly, but had a system io error that could not write back to ax (basically no type of Try…Catch statement) to say "I have a file/folder with duplicate name."  Hence, no info log generated that there was a success or failure… AX basically went on to the next sales order to post and invoice.

     

    RESOLUTION:

    So my first reaction here, is to delete the contents of the users local temp folder before every invoice run.  Although this works, there is still a 1-in-64k chance, that a duplicate file and folder name can be created when running invoices daily.  We did this for a few days, and most of the days ran without issues, but one day we did have 1 duplicate.  This was noticed because there was 1 .tmp file that was in the root of the Temp folder, which means there was a duplicate folder created before this one, and was moved to a temp folder with same name.

    We decided to do some AX code modification, to clean up that specific temp folder for that invoice after the classes to send mail to SMTP.  After it's sends the email, we don't need the folder anymore, it serves no purpose after it's sent.

    If you don't have the ability to do this at your company, you can run a scheduled task to clean up the folder, or manually clean yourself, if you are cautious about item in that temp folder that could be needed for system processes.

    I know this may all sound a bit confusing, but for those having the same troubles, you are free to contact me and I'd be glad to point you in the right direction.



    ------------------------------
    Rich Krol
    IT Business Analyst
    Applied Medical Technologies, Inc.
    Brecksville OH
    ------------------------------



  • 10.  RE: Batch invoice - Random missing info logs for print / email

    TOP CONTRIBUTOR
    Posted 09-27-2017 09:05 AM
    ​Awesome find Rich!

    ------------------------------
    Tony Zeigler
    Strategic Solutions NW, LLC
    Beaverton OR
    ------------------------------



  • 11.  RE: Batch invoice - Random missing info logs for print / email

    SILVER CONTRIBUTOR
    Posted 09-28-2017 11:57 AM
    Edited by Rich Krol 09-28-2017 11:57 AM
    I had some users message me looking specifically on what was changed, so I'll share what I can.   Our code is slightly different, for other modifications we have in the system, so I'll only share here at a minimum on what would be needed, to help you out.  Of course, compare with code you already have, and modify as appropriate.  I don't guarantee anything to work for you environment, so just be cautious, as with anything you do.

    In the SrsReportRunPrinter class, we modified the toEmail method.

    From comparing our code to the SYS layer, there is a comment labeled "// render the Report."  What we modified is below this, where the file name is created in the tempSubDirectory.  Changes you may need at a minimum (with whatever other custom code you may have in your class) are in BOLD ITALIC, surrounded by //EDIT and // <-- EDIT.

     

        // render the report

        files = this.renderReportToFile(attachmentFileName, fileFormat);

        if (files != null && files.lastIndex() > 0)

        {

            attachmentFileName = files.value(1);

            fileNameOnly =  reportContract.parmReportName() + SRSPrintDestinationSettings::findFileNameType(fileFormat, imageFormat);

     

            // rename the temp file and move to a unique directory to prevent problems when

            // multiple threads are emailing reports using the same temp directory

            tempSubDirectory = System.IO.Path::Combine(System.IO.Path::GetDirectoryName(attachmentFileName), System.IO.Path::GetFileNameWithoutExtension(attachmentFileName));

            System.IO.Directory::CreateDirectory(tempSubDirectory);

     

            attachmentPath = System.IO.Path::Combine(tempSubDirectory, fileNameOnly);

     

            // EDIT --> Check to make sure target doesn't already exist.  If it does, then delete it.  This is for any other batch job that might have ran

    // and made a tmp folder that could already be there, with an existing name.

     

            if (System.IO.File::Exists(attachmentPath))

            {

                System.IO.File::Delete(attachmentPath);

            }

            // <-- EDIT

     

            System.IO.File::Move(attachmentFileName, attachmentPath);

     

            if (this.parmReportRunMailer().emailReport(emailContract,attachmentPath,xreportname))

            {

                // The report has been successfully sent as attachment to email.

                info(strFmt('%1  to-%2 subj-%3', "@SYS344685", emailContract.parmTo(), emailContract.parmSubject() ));

     

            }

            else

            {

                // EDIT - Display an error in the infolog if email failed, so an end user can resend manually.

                warning(strFmt('%1  to-%2 subj-%3', "Failed to email report.", emailContract.parmTo(), emailContract.parmSubject() ));

            }

            // EDIT --> Cleanup temp file and directory, because once the document is emailed, we don't need the document nor

    // the folder.  It can always be reprinted from AX client if needed.

            System.IO.File::Delete(attachmentPath);             // Delete file

            System.IO.Directory::Delete(tempSubDirectory);      // Delete directory

            // <-- EDIT

        }



    ------------------------------
    Rich Krol
    IT Business Analyst
    Applied Medical Technologies, Inc.
    Brecksville OH
    ------------------------------



  • 12.  RE: Batch invoice - Random missing info logs for print / email

    Posted 10-11-2017 09:40 AM
    Many Thanks, Rich!!
    We were also facing the same issue for over 4 months.
    Our Batch invoice print had a failure rate of 20%.
    We looked into the temp folder and we had 12000+ .tmp folder.
    After deleting them, we have not experienced the issue anymore.
    We are also planning to do the code changes that were suggested by Rich.


    ------------------------------
    Souvik Sen
    B.G.E. Service & Supply
    Edmonton AB
    ------------------------------



  • 13.  RE: Batch invoice - Random missing info logs for print / email

    TOP CONTRIBUTOR
    Posted 9 days ago
    Hello!  I realize this thread is from 2017 - thanks to @Richard Wu​ for bringing to my attention!  We are having issues mentioned in this post.  However, I have checked the temp folder and there aren't any files in the temp folder related to the user running the batch job (*user*\AppData\Local\Temp).  So, now I am wondering why there aren't any files in the temp folder if there should be.  Could it be possible the files are being created somewhere else?  I do not see a setting which would direct where the file is saved.  If the resolution is deleting the temp files, is there another location the temp files can be?

    We are on AX 2012 RTM.

    Best regards and thank you in advance.
    Lori Holmes

    ------------------------------
    Lori Holmes
    Hamamatsu Corporation
    Bridgewater, NJ
    ------------------------------



  • 14.  RE: Batch invoice - Random missing info logs for print / email

    SILVER CONTRIBUTOR
    Posted 9 days ago
    It is possible there was a customization to put it into a different folder.  You could check Classes\SRSReportRunPrinter\toEmail and see if the Path was changed.  Ours was changed to mostly be in the same directory, just in a different folder.  In fact, each invoice was changed to be in its own folder with a different filename.  It is less possible to get a duplicate since I believe there are 10 or more characters now in the folder name, but it does still happen rarely; I guess random number generation isn't as random as we like to think (as mentioned in a Doctor Who episode).

    Also, the user name may not be the user of the batch.  It could be the business connector user.  AxProxy or AxBusConnect or whatever the business connector service name is.  Search the batch server users and look in all the temp folders; it is there somewhere.

    ------------------------------
    Richard Wu
    Bicon, LLC
    Boston MA
    ------------------------------