Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX (Archived)

Try Catch inner error to continue batch job process

(0) ShareShare
ReportReport
Posted on by 2,890

Hi all,

I've created a batch job in Dynamics AX 2012 that perform several packing slips at once, I want to keep the process running even if one of the orders fails, however when an order fails (for example, if the warehouse is not set in the line), then it never hits the catch sentence to keep running the process, I've tried something like this:

    try
    {    
        salesFormletter.run();
    } 
    catch(Exception::Error)
    {
        // Here I would add logic to keep the process running.  
    }


But it does not work, the class InventUpd_Physical throws an error in the method updatePhysicalIssue:

            if (! movement.inventTable().checkRefInventTrans(inventTrans)
            ||  ! movement.checkDimPhysical(inventTrans.Qty,inventDim,true))

            {
                throw error("@SYS18447");
            }


I'd like to catch that error and prevent it to kill the whole process, but it never hits my catch logic. Am I missing something? Thanks!

*This post is locked for comments

  • Denis Macchinetti Profile Picture
    Denis Macchinetti 16,444 on at
    RE: Try Catch inner error to continue batch job process

    Ok, now I got you.

    So, you handled the status in the catch of the SalesFormLetter class?

  • saman0suke Profile Picture
    saman0suke 2,890 on at
    RE: Try Catch inner error to continue batch job process

    Hi Dennis,

    I have a while select for all the orders I want to perform packing slip to, which are linked with another table that I also need to use, which status "Ok"; what I do in the catch statement (if any error is thrown, due to dimensions, inventory, etc) is to update the status in the second table to "Error" and retry, so in the next loop ignores the record with errors, do you think is time consuming? I'll check on your suggestion anyway, thanks!

  • Denis Macchinetti Profile Picture
    Denis Macchinetti 16,444 on at
    RE: Try Catch inner error to continue batch job process

    Hi Saman0suke

    If I understood correctly, your workaround is time consuming.

    Please, go through the classes mention before and follow the same strategy.

    So, call the SalesFormLetter class for each Sales Order.

    In this case you haven't manage any status or retry

  • Douglas Noel Profile Picture
    Douglas Noel 3,905 on at
    RE: Try Catch inner error to continue batch job process

    Hi,

    within X++ you can't catch exceptions within a transaction beside a UpdateConflict or an DuplicateKey exception to have a chance to react on this.

    You can't even skip simple CLRExecptions within a transaction (I mean standard CLRExeptions which haven't anything to do with database operations) having appl.ttslevel greater zero  For that case you can catch these simple CLRExceptions using some kind of own wrapper c# methods, which use standard .net exception handling.

    I think you should use single transactions in your case, if you really want to skip something, and if this is logically possible.

    Regards

    Douglas

  • saman0suke Profile Picture
    saman0suke 2,890 on at
    RE: Try Catch inner error to continue batch job process

    Thank you all for your help, I ended up using a retry call in the catch statement, it appears that it enters the catch statement but it was not doing what I wanted so I used a retry and changed a value in a custom field named "status" to error, so the next run ignores all the records with "error" status.

    Thanks again!

  • Denis Macchinetti Profile Picture
    Denis Macchinetti 16,444 on at
    RE: Try Catch inner error to continue batch job process

    Take a look to the standard class WmsShipmentPhysicalUpdBatchMulti, Run method that call the WmsShipmentPhysicalUpd_Sales class.

  • saman0suke Profile Picture
    saman0suke 2,890 on at
    RE: Try Catch inner error to continue batch job process

    Without a try/catch around the while select statement, will I be able to continue with the rest of the orders performing the packing slip process? how should that work if the method described above throws an error? that should break the while isn't? I would appreciate more details, thanks a lot!

  • Suggested answer
    Denis Macchinetti Profile Picture
    Denis Macchinetti 16,444 on at
    RE: Try Catch inner error to continue batch job process

    Hi

    In my opinion you must have a Run method where loop the Orders and call the SalesFormLetter class.

    If one order fails, the process will continue with another one.

    So, the main loop must not have Try.. Catch and no TTSBegin..TTSCommit.

    If you call the SalesFormLetter one time only, at the first issue, the entire process will rolled backed.

  • saman0suke Profile Picture
    saman0suke 2,890 on at
    RE: Try Catch inner error to continue batch job process

    Do you mean that the SalesFormLetter call should be outside of any tts in the batch job? Thanks!

  • Suggested answer
    Vilmos Kintera Profile Picture
    Vilmos Kintera 46,149 on at
    RE: Try Catch inner error to continue batch job process

    Check ttslevel. If you are inside a transaction (level > 0) at the point of calling your salesformletter, and there is an error inside, it will go out of that TTS transaction block with an abort.

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

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,458 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans