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 :
Finance | Project Operations, Human Resources, ...
Suggested Answer

How to develop batch job processes with continuation if error happens ?

(0) ShareShare
ReportReport
Posted on by 552

Hi guys,

As I'm only beginner, I would like to ask when we create a batch job processes which will process datasets (many records), and when we process each record then in the middle of it has error, how are we usually handling it to log the error but then also still able to continue its next records ?

I put my code in Try..Catch() block of code, so when it is error in the middle, it will catch the error and inside there is a procedure to insert to some log table, but currently when it happens, then it will stop the process and will not continue to next records.

Any simple existing process / class that I can follow along? or is there resource (blog) that have a good explanation about this that I can easily learn from it. Again I'm only beginner so if it too complex I can easily lost, or if it is too short, I won't know what to do or where to start or how.

Thanks in advance.

I have the same question (0)
  • Suggested answer
    Mohit Rampal Profile Picture
    12,565 Moderator on at

    Hi Ken, Please check this old thread

    www.dynamicsuser.net/.../59737

  • Ken Manhattan Profile Picture
    552 on at

    Hi Mohit,

    According to the link, on this sample :

    while (i <= 5)
    {
        try 
        {
             // This block "tries" to insert a record
    
             // … fill the buffer …
             table.insert();
        }
        catch (Exception::Error)
        {
            // If error occurs, don't break the execution.
            // You don't want to throw any exception from here,
            // but you can add some logging, for example.
        }
    }

    Should I put "retry" inside Catch block ? or just put i so the increment works ? also what does he mean by don't break the execution ? I can't put throw error() in this Catch(Error) block ?

    As a matter of fact, I put Throw Error() in each step of the processes 

    and it has few processes, from processing to create Sales Order, posting invoice, create payment journal, post payment journal, all in 1 batch job.

    Thanks,

  • Suggested answer
    Arunraj Rajasekar Profile Picture
    1,743 on at

    Hi Ken,

    You dont have to put "retry", just add info or warning to capture exception. From the example if there is an error in third record, then error will be captured inside the catch block and while loop will continue to process next record.

    i am not fully aware of your business scenario, processing all critical task under one batch may not be advisable.  

  • Ken Manhattan Profile Picture
    552 on at

    Hi Arunraj,

    Thanks for the advice. I will replace all the "throw error" with warning then.

    Anyway, I'm so intrigue to know what is actually the best solution for this kind of batch job, in general way at least.

    For my business scenario, understand this is too specific and I can't discuss here, but that is actually the needed: the batch job is pulling data from "staging table" from API processes which means there is a 3rd party application which processes their business and F&O will only need to process it to make the invoices as well as the payment because the invoice on the 3rd party also already paid over there.

    Basically with this requirement, the batch job in a single flow will create Sales Order, invoice it, create payment journal with its settlement. I understand this is too detail, so probably what is the correct concept for this ?

    Thanks again.

  • Suggested answer
    Arunraj Rajasekar Profile Picture
    1,743 on at

    Hi Ken,

    Before processing the records, write one or more methods to validate them. Add logic to those methods to catch as many fail instances as possible. refer below code
    All of the processes you described will have OOB classes to support and run them; try to use those as much as possible.

    While(i= #RetryNum)
            {
                error();
                continue;
            }
            else 
            {
                retry;
            }
        }
        
    }

  • Ken Manhattan Profile Picture
    552 on at

    Hi Arunraj,

    Thank you for this valuable info.

  • Dewanyagen Profile Picture
    6 on at
    Handling errors in batch job processes is crucial for maintaining data integrity. To ensure your batch job continues processing after encountering an error, you can implement error handling and logging within your Try..Catch block. One approach is to catch the error, log it to your error table, and then continue processing the next record. You can achieve this by encapsulating the processing logic for each record within its own Try..Catch block. If an error occurs, log it and move on to the next record.
    If you're interested in expanding your development skills, you might try to hire ruby developers. This website offers a guide on hiring Ruby developers that could provide you with insights into the skills and technologies involved.
  • Suggested answer
    Layan Jwei Profile Picture
    8,097 Super User 2025 Season 2 on at
    Hi Ken,

    So in your question, you first said that you want to process records, and if an error happens you don't want the process to stop but only log it and go to the next record.

    Then you said that you used "try catch" to achieve what you are looking for, but somehow when you did that, the process is being stopped. Can you please share with us your code to know why this is happening? I assume you in the catch you are using throw error("error"); instead of error("error");

    so basically if you do sth like that then it should work and the process should not stop in case of an error
    try
    {
    }
    catch
    {
      error("error");
    }
    Thanks,
    Layan Jweihan
    Please mark this answer as "Verified" if it solved your issue. In order to help others who will face a similar issue in the future

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 > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 664 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 522 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 303 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans