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, ...
Suggested Answer

Auto settlement for Customer payment journal using x++

(1) ShareShare
ReportReport
Posted on by 39
Hi,
 
I am working on creating a Customer Payment Journal for all unsettled invoices for a specific customer using a batch job (Parameter: customer account),
However, I've encountered an issue where the total amount for the settlements selected is not being updated in the LedgerJournalTrans table's AmountCurCredit (Credit) field and for the MarkedInvoice (Invoice) field.
 
while checking the settle trans, the lines are selected but the amount is not updated in the LedgerJournalTrans

this is my code for select the settlement against the customer:
 
public void settleCustomerInvoices(LedgerJournalTable  _LedgerJournalTable, CustAccount _custAccount)
    {
        CustTable custTable;
        CustTransOpen custTransOpen;
        CustTrans custTrans;
        SpecTrans spectrans,_specTrans;
        LedgerJournalTrans _LedgerJournalTrans;
        LedgerJournalCheckPost ledgerJournalCheckpost;
        custvendopentransmanager manager;
        AmountCur amountCur;
        select forupdate _LedgerJournalTrans where _LedgerJournalTrans.JournalNum == _LedgerJournalTable.JournalNum;
        
        manager = custvendopentransmanager::construct(_LedgerJournalTrans);
        
        if(manager.getSpecTransCount() == 0)
        {
            custTable = CustTable::find(_custAccount); //:findByLedgerDimension(_LedgerJournalTrans.LedgerDimension);
            
            while select custTransOpen where custTransOpen.AccountNum == custTable.AccountNum && custTransOpen.AmountCur > 0
                join custTrans where custTrans.RecId == custTransOpen.RefRecId && custTrans.AccountNum == custTransOpen.AccountNum
                notexists join specTrans where specTrans.RefRecId == custTransOpen.RecId
            {
                manager.updateTransMarked(custTransOpen,true);
                manager.updateSettleAmount(custTransOpen, custTransOpen.AmountCur);
            }
            
            ttsBegin;
            _LedgerJournalTrans.selectForUpdate(true);
            _LedgerJournalTrans.SettleVoucher = SettlementType::SelectedTransact;
            _LedgerJournalTrans.update();
            ttsCommit;
            
            try
            {
                ledgerJournalCheckPost = LedgerJournalCheckPost::newLedgerJournalTable(_LedgerJournalTable,NoYes::No);
                ledgerJournalCheckPost.run();
            }
            catch(Exception::Error)
            {
                error("Autosettlement Exception");
                if(manager.getSpecTransCount() > 0)
                {
                    manager.resetMarkedTrans();
                }
            }
        }
    }

I would appreciate guidance on ensuring the "AmountCurCredit" and "MarkedInvoice" field updates correctly.
I have the same question (0)
  • Jonas "Jones" Melgaard Profile Picture
    5,016 Most Valuable Professional on at
    Have you tried tracing how the standard application works?
     
    I don't remember exactly how the code works behind the scenes, but when I'm uncertain about how something functions, I use the trace parser tool to analyze the code path of the standard application and see when something gets updated.
     
  • Suggested answer
    Bill Ngo Profile Picture
    372 on at
    Hi Saran,
     
    There is a standard function like your custom function. It is very powerful. Why don't you use it? 
     
    You can check it in the All customers > Collect > Settle > Settle transactions.
     
     
    For the system automatically settles, you can read a introduction and activate a feature of "Settle customer payment deductions using the matching invoice" in the Feature management for your enhancement and practice. 

    "This feature adds an option that lets you choose to settle customer payment deductions using the invoice selected for each deduction. When you use this option, the system automatically settles deduction transactions using the matching invoice provided an open balance exists for that invoice; otherwise the deduction won't be settled automatically. Without this option, the system instead settles deduction transactions using the open amount for payment invoices, which was the standard behavior in Supply Chain Management version 10.0.24 and earlier."

    Regards,
    Bill
  • Suggested answer
    Anton Venter Profile Picture
    20,680 Super User 2026 Season 1 on at
    Add your code to the forum post using the "Insert Code Snippet" button, it makes it easier to read :-).
     
    There are many examples in the standard application. How do you find examples? In case you don't know, in the Visual Studio Application Explorer, right click the MarkedInvoice field on the LedgerJournalTrans table and select Find References.
     
    To update the LedgerJournalTrans line amount, keep a running total of each transaction that will be settled and update the LedgerJournalTrans line amount. Or as others have already mentioned, take a look how the standard application does it.
     
    
    ledgerJournalTrans.MarkedInvoice = custTrans.Invoice;
    ledgerJournalTrans.MarkedInvoiceCompany = custTrans.company();
    ledgerJournalTrans.MarkedInvoiceRecId = custTransOpen.RecId;
    ledgerJournalTrans.SettleVoucher = SettlementType::SelectedTransact;
     
  • Anton Venter Profile Picture
    20,680 Super User 2026 Season 1 on at
    Has your question been answered? If so, mark the post as answered to help others in the future.

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... 608 Super User 2026 Season 1

#2
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 564

#3
CP04-islander Profile Picture

CP04-islander 396

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans