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

Mass reverse closed customer sales transactions error x++ job

(0) ShareShare
ReportReport
Posted on by 2,654

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

  • Suggested answer
    Kauto Profile Picture
    Kauto 2,654 on at
    RE: Mass reverse closed customer sales transactions error x++ job

    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.

  • Verified answer
    OsmanIstanbul Profile Picture
    OsmanIstanbul 2,814 on at
    RE: Mass reverse closed customer sales transactions error x++ job

    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

  • Kauto Profile Picture
    Kauto 2,654 on at
    RE: Mass reverse closed customer sales transactions error x++ job

    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;
            }
        }

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,436 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans