AX2009 Settle Customer Open Transcation

TL;DR: AX2009 Settle Customer Open Transcation with X++


We have sometimes the problem in AX2009 that a voucher was posted the settle an open transaction of a customer but only a partial amount has been settled. So the job search all open transaction that should have been closed and settles them.

AX2009 Job

static void down1_SettleCustOpenTransactions(Args _args)
    SpecTransManager    lclsSpecTransManager;
    CustTrans           ltabCustTrans, ltabCustTransSelect;
    CustTrans           ltabCustTransSecond;
    CustTransOpen       ltabCustTransOpen, ltabCustTransOpenSelect;
    CustSettlement      ltabCustSettlement;
    CustTable           ltabCustTable;
    boolean             lbolSettle;
    Set                 lsetRecIds = new Set(Types::Int64);
    int                 i;

    while select ltabCustTable
     exists join ltabCustTransSelect
           where ltabCustTransSelect.AccountNum == ltabCustTable.AccountNum
     exists join ltabCustTransOpenSelect
           where ltabCustTransOpenSelect.AccountNum == ltabCustTable.AccountNum
              && ltabCustTransSelect.RecId          == ltabCustTransOpenSelect.RefRecId
              && ltabCustTransSelect.AmountCur      != ltabCustTransOpenSelect.AmountCur
        i++; print i;
        lbolSettle = false;
        while select ltabCustTrans
               where ltabCustTrans.Invoice
                  && ltabCustTrans.AccountNum   == ltabCustTable.AccountNum
                  && ltabCustTrans.AmountCur    >  0
                join firstOnly ltabCustTransOpen
               where ltabCustTransOpen.RefRecId == ltabCustTrans.RecId
                join firstOnly ltabCustSettlement
               where ltabCustSettlement.TransRecId  == ltabCustTrans.RecId
                join firstOnly ltabCustTransSecond
               where ltabCustTransSecond.AccountNum == ltabCustTrans.AccountNum
                  && ltabCustTransSecond.Voucher    == ltabCustSettlement.OffsetTransVoucher
            if (
            if (ltabCustTransOpen && abs(ltabCustTrans.remainAmountCur()) && abs(ltabCustTrans.remainAmountCur()) == abs(ltabCustTransSecond.remainAmountCur()))
                lclsSpecTransManager = SpecTransManager::construct(ltabCustTable);
                lclsSpecTransManager.insert(curExt(), tableNum(CustTransOpen), ltabCustTransSecond.transOpen().RecId, ltabCustTransSecond.remainAmountCur(), ltabCustTransSecond.CurrencyCode);
                lclsSpecTransManager.insert(curExt(), tableNum(CustTransOpen), ltabCustTrans.transOpen().RecId, ltabCustTrans.remainAmountCur(), ltabCustTransSecond.CurrencyCode);
                lbolSettle = true;
        if (lbolSettle)
            CustTrans::settleTransact(ltabCustTable, null, true, SettleDatePrinc::SelectDate, systemDateGet());
Originally published July 28, 2023 | View revision history

If you enjoyed this post, you might also enjoy:


MS Dynamics AX / D365 FO developer with experience in administration, developing new and adjusting the existing solutions in the Dynamics AX 2009, AX 2012, D365 FO. Ability to support all phases of implementation of project, starting with design, development, final deployment and administration. Responsible team member always looking for new challenges with experience from international projects in Austria, Germany and Switzerland. Experience in implementation of external service to MS Dynamcis AX / D365, like cash registers and warehouse automations. More about the author →