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

Community site session details

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

Settle customer's all open invoices & payment using x++

(0) ShareShare
ReportReport
Posted on by 94

Hi All,

I need your support to make customization to settle all open transaction of a customer.

I am using D365F&O version 10.0.21.

any help highly appreciated.

Thanks

i have already applied this below code but it is not working.. No error!

custTable = CustTable::find(settlement.CustAccount);

// Find the oldest invoice that has not been settled yet
// for this customer you can customize the query find the invoice that you want to settle
select firstonly invCustTrans
order by TransDate asc
where invCustTrans.AccountNum == custTable.AccountNum &&
invCustTrans.TransType == LedgerTransType::Sales &&
!invCustTrans.LastSettleDate;

// Find the oldest payment that has not been settled yet
// for this customer
select firstonly payCustTrans
order by TransDate asc
where payCustTrans.AccountNum == custTable.AccountNum &&
payCustTrans.TransType == LedgerTransType::Payment &&
!payCustTrans.LastSettleDate;

ttsbegin;

//Mark for settlement
specTransExecutionContext = SpecTransExecutionContext::newFromSource(custTable);
specTransManager = SpecTransManager::construct(specTransExecutionContext.parmSpecContext());

specTransManager.insert(invCustTrans.dataAreaId, invCustTrans.TableId, invCustTrans.RecId, invCustTrans.AmountCur, invCustTrans.CurrencyCode, NoYes::No);
specTransManager.insert(payCustTrans.dataAreaId, payCustTrans.TableId, payCustTrans.RecId, payCustTrans.AmountCur, payCustTrans.CurrencyCode, true);

//Settle
CustTrans::settleTransaction(
specTransExecutionContext,
CustTransSettleTransactionParameters::construct());
ttscommit;

I have the same question (0)
  • André Arnaud de Calavon Profile Picture
    299,947 Super User 2025 Season 2 on at
    RE: Settle customer's all open invoices & payment using x++

    Hi Tech Talks Dynamics Community,

    Have you already used the debugger to find out if your code is working and if all variables and table buffers do have the correct value? E.g. you start your coding with finding a customer based on "settlement.CustAccount". Is this passing the correct customer value?

  • huijij Profile Picture
    19,811 on at
    RE: Settle customer's all open invoices & payment using x++

    Hi Sir,

    Please refer to the old thread to see if it helps:

    community.dynamics.com/.../settle-customer-invoices

  • Eng.khan Profile Picture
    94 on at
    RE: Settle customer's all open invoices & payment using x++

    Hi Andre,

    Thanks for your reply, yes i have checked and rectify the issue, it is know ok.

    But as you can see it is settle the last open transactions. can you please suggest to settle all open invoices for a specific customer at one short

    Thanks

  • André Arnaud de Calavon Profile Picture
    299,947 Super User 2025 Season 2 on at
    RE: Settle customer's all open invoices & payment using x++

    Instead of selecting one payment and one invoice, you have to create a loop for it with help of e.g. 'while select'.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Pallavi Phade – Community Spotlight

We are honored to recognize Pallavi Phade as our Community Spotlight honoree for…

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

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 684 Super User 2025 Season 2

#2
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 588

#3
Martin Dráb Profile Picture

Martin Dráb 542 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans