Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested answer

How to get a list of payments for an sales invoice

(0) ShareShare
ReportReport
Posted on by 5

I am integrating our third party app with a clients NAV 2015 on-site server.

I need to add the ability to get a list of payments that have been entered into NAV for a specific sales invoice but I can't find documentation on how to do this.

I'm assuming I have to query either the General or Customer ledger but I'm completely new to working on NAV API's and I don't know how the data is related.  The current implementation I am updating is using SOAP queries if that helps.

  • StuartMc Profile Picture
    StuartMc 5 on at
    RE: How to get a list of payments for an sales invoice

    Hi Suresh.  Thank you for your answer. it is helping me though I am doing this in a C# console application so I am trying to convert your logic to C# code using SOAP Web References (not my doing).

    The way the previous dev "attempted" this was in our system, a third party application that integrates with Nav, we get a list of invoice numbers to check the status of them in a customers Nav system.  He then queries the "SalesInvoiceAndCredit" web service for that Invoice.  What he doesn't do is check the Customer or General ledgers for payments.  

    This is where I come in having taken over from the previous dev.  

    A couple of questions I have that I hope you can answer:

    1. Do I need to query the SalesInvoiceAndCredit service if I'm mainly looking for the status of the invoice and what payments have been made?
    2. Can I set the search filter to find more than one sales invoice? i.e. in c# I call the "ReadMultiple" function of the service and pass it a filter array.
      SalesInvoiceAndCredit_Filter[] Filter = new List() {
          {
              new SalesInvoiceAndCredit_Filter() { field = External_Document_No, Criteria = "INVOICE A" },
              new SalesInvoiceAndCredit_Filter() { field = External_Document_No, Criteria = "INVOICE B" }
          }
      }.ToArray();
    3. The results using the above filter example only returns "INVOICE B".  Can I provide a list on invoice numbers to return?  or do I have to make a call to the API for each one separately?
    4. When I query the Customer Ledger for document of type "PAYMENT" I can't see any obvious reference to an invoice.  How do payment entries reference what they are a payment for?

    Thank you

  • StuartMc Profile Picture
    StuartMc 5 on at
    RE: How to get a list of payments for an sales invoice

    Thank you Suresh... That is helpful.

    I am programming this in C# so I'm not certain what language you've used there.  Here is my interpretation of it.  Please let me know if I am understanding this correctly.

    • Line 1 gets a list of Customer Ledger Entries returning just the "Document Type", "Customer Number", "Posting Date" and "Currency Code".
    • Line 2 filters the list to show only entries where the "document type" is "Invoice"
    • Line 3 filters the list to show only entries where the "customer number" is the same as the Sale Invoice's "bill to customer no" from the header information
    • Line 4 filters the list to show only entries where the "order no" is the same as the sales invoice's "Number" from the header information
    • Lines 5, 6 and 10 are simply a check to see if there are any results and the start and end of a loop to iterate through the results
    • Lines 7 and 8 should get a single detailed item from the customer ledger entries based on the results by matching the "Customer Ledger Entry Number" where the Entry Type is "Application".

    Do you know where I can find good documentation regarding achieving this in C#?

  • StuartMc Profile Picture
    StuartMc 5 on at
    RE: How to get a list of payments for an sales invoice

    Thank you Suresh... That is helpful.

    I am programming this in C# so I'm not certain what language you've used there.  Here is my interpretation of it.  Please let me know if I am understanding this correctly.

    • Line 1 gets a list of Customer Ledger Entries returning just the "Document Type", "Customer Number", "Posting Date" and "Currency Code".
    • Line 2 filters the list to show only entries where the "document type" is "Invoice"
    • Line 3 filters the list to show only entries where the "customer number" is the same as the Sale Invoice's "bill to customer no" from the header information
    • Line 4 filters the list to show only entries where the "order no" is the same as the sales invoice's "Number" from the header information
    • Lines 5, 6 and 10 are simply a check to see if there are any results and the start and end of a loop to iterate through the results
    • Lines 7 and 8 should get a single detailed item from the customer ledger entries based on the results by matching the "Customer Ledger Entry Number" where the Entry Type is "Application".

    Do you know where I can find good documentation regarding achieving this in C#?

  • StuartMc Profile Picture
    StuartMc 5 on at
    RE: How to get a list of payments for an sales invoice

    Thank you Suresh... That is helpful.

    I am programming this in C# so I'm not certain what language you've used there.  Here is my interpretation of it.  Please let me know if I am understanding this correctly.

    • Line 1 gets a list of Customer Ledger Entries returning just the "Document Type", "Customer Number", "Posting Date" and "Currency Code".
    • Line 2 filters the list to show only entries where the "document type" is "Invoice"
    • Line 3 filters the list to show only entries where the "customer number" is the same as the Sale Invoice's "bill to customer no" from the header information
    • Line 4 filters the list to show only entries where the "order no" is the same as the sales invoice's "Number" from the header information
    • Lines 5, 6 and 10 are simply a check to see if there are any results and the start and end of a loop to iterate through the results
    • Lines 7 and 8 should get a single detailed item from the customer ledger entries based on the results by matching the "Customer Ledger Entry Number" where the Entry Type is "Application".

    Do you know where I can find good documentation regarding achieving this in C#?

  • Suggested answer
    Suresh Kulla Profile Picture
    Suresh Kulla 44,656 on at
    RE: How to get a list of payments for an sales invoice

    Yes you need to query the customer ledger entry table based on the customer and then review the detail customer ledger entries of that customer ledger entry to review the applications, something like below

       

     CustledgEntry.SETCURRENTKEY("Document Type","Customer No.","Posting Date","Currency Code");
          CustledgEntry.SETRANGE("Document Type",CustledgEntry."Document Type"::Invoice);
          CustledgEntry.SETRANGE("Customer No.",SalesHeader."Bill-to Customer No.");
          CustledgEntry.SETRANGE("Order No.",SalesHeader."No.");
          IF CustledgEntry.FINDSET THEN
            REPEAT
              DetailedCustLedgEntry.SETRANGE(DetailedCustLedgEntry."Cust. Ledger Entry No.", CustledgEntry."Entry No.");
              DetailedCustLedgEntry.SETRANGE("Entry Type", DetailedCustLedgEntry."Entry Type"::Application);
              //// do any logic
              UNTIL CustledgEntry.NEXT = 0
              

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,409 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans