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, ...
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
    303,571 Super User 2026 Season 1 on at

    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

    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

    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
    303,571 Super User 2026 Season 1 on at

    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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

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

#1
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 493

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 413 Super User 2026 Season 1

#3
Syed Haris Shah Profile Picture

Syed Haris Shah 242 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans