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)

Try Catch inner error to continue batch job process

(0) ShareShare
ReportReport
Posted on by 2,894

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

I have the same question (0)
  • Suggested answer
    Vilmos Kintera Profile Picture
    46,149 on at

    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.

  • saman0suke Profile Picture
    2,894 on at

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

  • Suggested answer
    Denis Macchinetti Profile Picture
    16,444 on at

    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
    2,894 on at

    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!

  • Denis Macchinetti Profile Picture
    16,444 on at

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

  • saman0suke Profile Picture
    2,894 on at

    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!

  • Douglas Noel Profile Picture
    3,905 on at

    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

  • Denis Macchinetti Profile Picture
    16,444 on at

    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

  • saman0suke Profile Picture
    2,894 on at

    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
    16,444 on at

    Ok, now I got you.

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

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