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, ...
Answered

Customer Statements Sent Multiple times in AR Batch Job

(5) ShareShare
ReportReport
Posted on by 174
Hi All, 
 
We are sending Customer Account Statements from the AR - Periodic Tasks - Customer account statement. Whatever settings we do the emails are being sent multiple times (6 times). I have found this post ( Link) to do some settings on the Batch Task Details; however, we are not able to "Withhold" the Batch job which was started from AR. The only option is to Cancel the batch job which surprisingly works for us as it completes one iteration and cancels the job, but this is not the ideal way to do it. 
 
We have tried to create the batch job directly from System Administration - Enquiries - Batch jobs but are stuck with the errors. 
 
 
Categories:
I have the same question (0)
  • Suggested answer
    Holly Huffman Profile Picture
    6,538 Super User 2025 Season 2 on at
    Good morning, afternoon, or evening depending on your location!
     
    This issue is a known challenge with customer account statement batch jobs in AR. The problem arises because, starting with version 10.0.27 and later, batch tasks have retries enabled by default. When the system encounters even minor errors during email processing in nonidempotent tasks (like sending customer statements), it triggers a retry process. This ends up re-sending the same email multiple times (in your case, six times) instead of processing them only once.
     
    What’s Happening?
    • Batch Task Retries: The AR batch job for customer statements uses a specific run class. When an error (or an apparent error) occurs, the batch framework automatically retries the task—even if part of the job has already executed (i.e., sending the email).
    • NonIdempotent Task Issue: Since sending emails is not idempotent (resending produces duplicate emails), each retry results in additional copies being sent.
    • Default Behavior: Unfortunately, there’s no builtin “withhold” option for ARoriginated batch jobs, which means the system will reattempt sending until the maximum retry count is reached or until you cancel the job.
     
    Workaround: Disable Retries for the Customer Statement Batch
    A common workaround is to use an extension on the Batch table that sets the maximum retries (RetriesOnFailure) to zero for the specific run class handling customer account statements. This prevents the framework from retrying if an error is encountered.
    Example Code Snippet
    Below is an example of an X++ extension that sets retriesOnFailure to 0 when the batch job run class matches the customer statement controller (you may need to adjust the exact run class name depending on your implementation):
    [ExtensionOf(tableStr(Batch))]
    final class Batch_Extension
    {
        public void insert(BatchInfo batchInfo)
        {
            // Check if the batch run class is for customer account statements
            if (batchInfo && batchInfo.parmRunClass() is CustAccountStatementController)
            {
                // Set the retries on failure to 0 to disable auto-retries
                this.retriesOnFailure = 0;
                batchInfo.parmRetriesOnFailure(0);
            }
           
            next insert(batchInfo);
        }
    }

    Note:
    • Replace CustAccountStatementController with the actual class used in your environment for sending customer statements if it differs.
    • Make sure to compile and deploy this extension in your environment and test it thoroughly in a non-production setting before applying it live.
     
    Next Steps
    1. Implement the Extension: Add this extension to your D365FO environment to enforce a zeroretry policy for customer statement batch jobs.
    2. Cancel Current Jobs: Until the extension is in place, you might need to cancel the duplicatesending job after one iteration as a temporary workaround.
    3. Monitor Batch Job Behavior: Postimplementation, monitor the AR batch job to ensure that the emails are sent only once.
     
    This approach directly addresses the root cause of duplicate emails by stopping the retry mechanism for this specific batch process. If you still encounter issues or need additional adjustments, exploring further customization or consulting Microsoft support may be necessary.
     
    Please note: I teamed up with CoPilot AI to research and craft the best response to your question!
    Hope this helps some!
  • Jonas "Jones" Melgaard Profile Picture
    4,988 Most Valuable Professional on at
     
    Please wait changing any code as suggested by other replies.
     
    My immediate assumption is that the reason for the 6 emails is that F&O has configured the batch with a retry policy.
     
    If one of the statements fails, it will try and try again until it gives up.
     
     
    Try to change this to 0 from the user interface, in your existing batch job, and see if it works.
  • DC Dynamics 365 Profile Picture
    174 on at
    Hi Jonas, 
     
    The issue we have is when we start the Batch job from AR we cannot edit it from System Administration - Enquiries - Batch Jobs as it in "Executing" stage already. 
    I guess we could try setting the start date a bit later, does this create the Batch Job and put it into "Waiting" or "Withhold" status. The only workaround I see at the moment is to cancel the job. 
  • Verified answer
    Jonas "Jones" Melgaard Profile Picture
    4,988 Most Valuable Professional on at
    Ah that way, you don't have recurrence. I'm really sorry
     
    In case you schedule them manually without recurrence, you can always schedule it to run in, for example, 10 minutes in the future.
    That allows you to test if the retry parameter fixes it. 
     
    Question is, however, if it makes sense to have it run with recurrence?
    But if it's a part of your daily process, then you might consider writing code as a work-around.
    The code in the reply originates from this article, in case you want to know the history behind it: https://ax.docentric.com/forum/t/bug-with-batch-jobs-repeating-email-sending-when-printing-customer-account-statement-report/410
     
    As a side note: We should figure out why it's failing. I.e. is there an issue with a customer?
    Consequence is that some customers might not receive their account statement.

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
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 420 Most Valuable Professional

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 241 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans