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, ...
Answered

Code to fetch customer balance on basis of asOfdate parameter

(0) ShareShare
ReportReport
Posted on by 39
Hello,
 
Can anyone help me, how can we fetch the Customer Balance amount on basis of date like asOfdate.
 
 
I have the same question (0)
  • Martin Dráb Profile Picture
    236,962 Most Valuable Professional on at
    Code to fetch customer balance on basis of asOfdate parameter
    I see that code in your other thread is actually from D365 F&O, not Dynamics AX. Isn't this question about F&O too?
  • Nikita Mhamane Profile Picture
    39 on at
    Code to fetch customer balance on basis of asOfdate parameter
    Thank you for the reply.
     
    Yes ,both the threads are from D365 F&O.
     
    I will move this to finance forum.
  • Hana Xue Profile Picture
    Microsoft Employee on at
  • Nikita Mhamane Profile Picture
    39 on at
    Code to fetch customer balance on basis of asOfdate parameter
    Hello hana,
     
    The link is not working for me.
  • André Arnaud de Calavon Profile Picture
    300,160 Super User 2025 Season 2 on at
    Code to fetch customer balance on basis of asOfdate parameter
    Hi Nikita,
     
    You can sum all CustTrans records per customer setting a range on the transaction date. 
  • Hana Xue Profile Picture
    Microsoft Employee on at
    Code to fetch customer balance on basis of asOfdate parameter
    Hi Nikita,
    You can refer to the code shown in the screenshot, it may not be accurate, but you can refer to it to get inspiration.
    In this code, first specify the "asOfDate" and then select the sum of the field from records for the specified customer () where the transaction date is less than or equal to the "asOfDate."

    Best Regards,
    Hana
  • Suggested answer
    Nikita Mhamane Profile Picture
    39 on at
    Code to fetch customer balance on basis of asOfdate parameter
    Hello Everyone,
     
    Thank you for the response!!
     
    I got the solution as -
     
      while select sum(AmountMST) from custTrans
                 where custTrans.AccountNum == custTable.AccountNum
                 && custTrans.TransDate <= balDate
            {
                BalanceTmp.BalAmount = custTrans.AmountMST; // Total Balance
            }
                BalanceTmp.OpeningBalance = custTable.openBalanceMST(balDate);
  • Verified answer
    Martin Dráb Profile Picture
    236,962 Most Valuable Professional on at
    Code to fetch customer balance on basis of asOfdate parameter
    By the way, there is no need for a while select, because your query won't ever return more than a single record. It summarizes all records together (without any grouping). Therefore your code can be refactored to this:
    select sum(AmountMST) from custTrans
        where custTrans.AccountNum == custTable.AccountNum
           && custTrans.TransDate <= balDate;
           
    balanceTmp.BalAmount = custTrans.AmountMST; // Total Balance
    balanceTmp.OpeningBalance = custTable.openBalanceMST(balDate);

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... 703 Super User 2025 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 582 Most Valuable Professional

#3
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 542

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans