AX2009 Recalculate Vendor Cash Disc

TL;DR: AX2009 Recalculate Vendor Cash Disc with X++


With this job you can recalculate the cash disc amount in the vendor open transactions. You can change the query to filter different transactions.

AX2009 Job

static void down1_VendRecalcCashDisc(Args _args)
    VendTransCashDisc   ltabVendTransCashDisc;
    VendTransOpen       ltabVendTransOpen;
    VendTrans           ltabVendTrans;
    VendInvoiceJour     ltabVendInvoiceJour;
    int                 i;

    while select ltabVendTrans
           where ltabVendTrans.CashDiscCode != ""
//&& (ltabVendTrans.AmountCur > 0.36 || ltabVendTrans.AmountCur < -0.36)
            join ltabVendTransOpen
           where ltabVendTransOpen.RefRecId == ltabVendTrans.RecId
  notexists join ltabVendTransCashDisc
           where ltabVendTransCashDisc.RefTableId       == ltabVendTransOpen.TableId
              && ltabVendTransCashDisc.RefRecId         == ltabVendTransOpen.RecId
              && ltabVendTransCashDisc.CashDiscAmount   != 0
        ltabVendInvoiceJour = VendInvoiceJour::findFromVendTrans(ltabVendTrans.Invoice, ltabVendTrans.TransDate, ltabVendTrans.AccountNum);

        info(ltabVendTrans.AccountNum + " " + ltabVendTrans.Invoice + " " + ltabVendInvoiceJour.createdBy);

        ltabVendTransCashDisc.calcCashDisc(ltabVendTrans.CurrencyCode, ltabVendTrans.AmountCur, ltabVendTrans.DueDate,
            ltabVendTrans.DocumentDate ? ltabVendTrans.DocumentDate : ltabVendTrans.TransDate,
            ltabVendTrans.CashDiscCode, ltabVendTransOpen.TableId, ltabVendTransOpen.RecId);

        if (ltabVendTrans.AmountCur < -1 || ltabVendTrans.AmountCur > 1)
    info(strfmt("Count of mutated entries: %1",i));
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 →