web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Mass reverse closed customer sales transactions error x++ job

(0) ShareShare
ReportReport
Posted on by 2,734

I am looking for the best way to mass simulate the reverse button for a large batch of customer invoices and payments that need to be unsettled.

I am reviewed a few blogs on this site and I have tried using the following but even though the settlement was performed a month ago in an open period, the system is going back to the date of the transaction itself and giving the following error:

Reversal denied. The transaction is in a previous accounting year.

Here is the code sample:

CustTrans                   custTrans;
    TransTxt                    txt;
    Counter                     counter = 0;
    boolean                     reversed;
    Voucher                     voucher = 'SSCNV00796948';
    TransactionReversal_Cust    transsactionCust = new TransactionReversal_Cust();
    Args                        args = new Args();
    ;

    while select custTrans
        where custTrans.Voucher == voucher
    {
        //Returns the reversed status
        reversed = TransactionReversalTrans::findTransactionReversalTrans(tableNum(CustTrans), custTrans.RecId).Reversed;

        if(!reversed)
        {
            args.record(custTrans);
            transsactionCust.parmReversalDate(systemDateGet());
            transsactionCust.run();
            
            new MenuFunction(menuitemActionStr(TransactionReversal_Cust), MenuItemType::Action).run(args);
            counter  ;
        }
    }

    info(strFmt('Transaction %1 reversed, transaction count %2',voucher,counter));

Can someone provide me with a quick sample script where I can provide invoiceID or voucher number that is settled and be able to reverse?

Thank you

I have the same question (0)
  • Kauto Profile Picture
    2,734 on at

    I have also been trying to test manual reversal of closed transactions and I am getting the following error once I MARK the transactions and then hit REVERSE

    Cannot edit a record in Customer settlement (CustSettlement).

    An update conflict occurred due to another user process deleting the record or changing one or more fields in the record.

    Has anyone come across this issue when attempting the process manually?

    I think the following script I have now is working but I get the same exception running the script and doing it manually

    CustTable           custTable;
        CustTrans           findCustTrans;
        Voucher             voucher = 'SSCNV00796948';
        AmountCur           balanceAmount;
        CustSettlement      custSettlement;
        SpecTransManager    specTransManager;
        
        
        select firstonly * from findCustTrans
            where findCustTrans.Voucher == voucher;
    
        if (findCustTrans.RecId)
        {
            balanceAmount = findCustTrans.remainAmountCur();
    
            if (balanceAmount == 0)
            {
                custTable = custTable::find(findCustTrans.AccountNum);
    
                ttsBegin;
                select forUpdate firstonly custSettlement
                    where custSettlement.TransCompany == findCustTrans.dataAreaId
                    && custSettlement.TransRecId == findCustTrans.RecId
                    && custSettlement.AccountNum == findCustTrans.AccountNum;
    
                if(CustSettlement)
                {
                    ttsBegin;
                    specTransManager = SpecTransManager::newRefTableId(custTable, tablenum(custSettlement), true);
                    specTransManager.insert(custSettlement.DataAreaId, custSettlement.TableId, custSettlement.RecId, custSettlement.SettleAmountCur, findCustTrans.CurrencyCode);
    
                    custSettlement.CustVendSettlement::markOffsets(specTransManager, findCustTrans.CurrencyCode, true);
                    ttsCommit;
    
                    if (CustTrans::reverseTransact(custTable, custSettlement.TransDate, settleDatePrinc::DateOfPayment))
                    {
                        specTransManager.deleteAll();
                    }
                }
                ttsCommit;
            }
        }

  • Verified answer
    OsmanIstanbul Profile Picture
    2,820 on at

    Hi,

    for the first question: you can reverse all settlements, just keep in mind your reverse date. you should select today's date or selected date instead.

    the error that you get for manual reversal might be about dirty data occurring with a non-correct update.

    Best

  • Suggested answer
    Kauto Profile Picture
    2,734 on at

    I believe I found the issue on this - the code I was using was asking to use the date stamped against the customer settlement for the reversal date - even though the period is still open this was the cause of the update conflict.

    Changing to using systemDateGet() for the reversal date allowed my second script to work correctly - albeit very slowly.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 632 Super User 2026 Season 1

#2
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 624

#3
CP04-islander Profile Picture

CP04-islander 301

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans