Bug with batch jobs repeating email sending when printing Customer Account Statement report

If a batch job for sending emails seems to be duplicating emails, this may be the cause.

From version 10.0.27 onwards batch tasks have retries enabled by default, which are triggered whenever an error occurs. Relevant Microsoft documentation can be found here.

The problem with this is that if a task isn’t idempotent (sending emails for example isn’t), the task should not be retried on error, but because the error happens regardless of idempotence, the task result is repeated.

In the case of emails this means that if an email fails to send (throws any error), all the emails that have already been sent before are sent again.

We encourage you to report this bug to Microsoft, so that it gets resolved as soon as possible.

Currently there is a workaround of setting the maximum retries per batch task to 0, so that this new logic doesn’t trigger. This can be accomplished by extending the insert method of the Batch table, like this:

[ExtensionOf (tableStr(Batch))]
final class Batch_Extension
{

    public void insert(BatchInfo batchInfo)
    {
        if (batchInfo && batchInfo.parmRunClass() is CustAccountStatementExtController)
        {
            this.retriesOnFailure = 0;
            batchInfo.parmRetriesOnFailure(0);
        }

        next insert(batchInfo);
    }

}
1 Like

This issue also happens for sales invoice report and in that case the code looks a little different:

[ExtensionOf (tableStr(Batch))]
final class Batch_Extension
{

    public void insert(BatchInfo batchInfo)
    {
        if (batchInfo && batchInfo.parmRunClass() is SalesInvoiceController)
        {
            this.retriesOnFailure = 0;
            batchInfo.parmRetriesOnFailure(0);
        }

        next insert(batchInfo);
    }

}

This issue also happens for Customer (and probably Vendor) bank payment advice. For these cases the code looks like this:
Customer:

[ExtensionOf (tableStr(Batch))]
final class Batch_Extension
{

    public void insert(BatchInfo batchInfo)
    {
        if (batchInfo && batchInfo.parmRunClass() is BankPaymAdviceCustControllerV2)
        {
            this.retriesOnFailure = 0;
            batchInfo.parmRetriesOnFailure(0);
        }

        next insert(batchInfo);
    }

}

Vendor:

[ExtensionOf (tableStr(Batch))]
final class Batch_Extension
{

    public void insert(BatchInfo batchInfo)
    {
        if (batchInfo && batchInfo.parmRunClass() is BankPaymAdviceVendControllerV2)
        {
            this.retriesOnFailure = 0;
            batchInfo.parmRetriesOnFailure(0);
        }

        next insert(batchInfo);
    }

}

From what I can tell on Yammer the issue is still being reported and thus doesn’t seem to be fixed yet up-to at least version 10.0.31 (link to Yammer post here).