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 :
Small and medium business | Business Central, N...
Suggested Answer

Add Ext Doc No to Statement

(7) ShareShare
ReportReport
Posted on by 105
I need to add the External Document number from a Sales Order to the Customer Statement. I think I am close.
 
Here is what I have...
 
Any suggestions are appreciated.
 
Thanks.
reportextension 50100 CustomerStatementReportExt extends "Standard Statement"
{
    dataset
    {
        modify(DtldCustLedgEntries)
        {
            column(SalesOrderExternalNo; SalesOrderExternalNo)
            {
                Caption = 'External Document No.';
            }
 
            trigger OnAfterGetRecord()
            begin
                SalesOrderExternalNo := '';
                // Only populate for Sales Orders
                if DtldCustLedgEntries."Document Type" = DtldCustLedgEntries."Document Type"::Order then
                    if SalesHeader.Get(DtldCustLedgEntries."Document Type", DtldCustLedgEntries."Document No.") then
                        SalesOrderExternalNo := SalesHeader."External Document No.";
            end;
        }
    }
 
    var
        SalesHeader: Record "Sales Header";
        SalesOrderExternalNo: Text[100];
}
I have the same question (0)
  • Suggested answer
    YUN ZHU Profile Picture
    101,600 Super User 2026 Season 1 on at
    Hi, There is no Order in the Document Type of Detailed Customer Ledger Entries. . .Your code cannot be used to get the order. I don't understand why there is no error. Did you add Order Type in your environment?
    Because this is a posted table, you can use the Invoice No. to get the External Document number on the Posted Sales Invoice. There is no problem.
     
     
    Hope this helps.
    Thanks.
    ZHU
  • Suggested answer
    OussamaSabbouh Profile Picture
    16,916 Super User 2026 Season 1 on at
    Hello,

    Statements use posted entries, not open Sales Orders.
    So instead of reading from Sales Header, pull External Document No. from the Cust. Ledger Entry linked to each detailed entry:

    if CLE.Get(DtldCustLedgEntries."Cust. Ledger Entry No.") then
        ExtDocNo := CLE."External Document No.";

    Regards,
    Oussama
  • Suggested answer
    Pallavi Phade Profile Picture
    5,683 Super User 2026 Season 1 on at
     
    You can get External Documnet No , You need to fetch it from Customer Ledger . Write Small AL code on "Detailed Customer LEdger Enties"
     
     
    In Detailed Customer Ledger Entries , You have customer ledger entry no , small customization you can extract external document no based on customer ledger entry no
     
     
     
    Regards
    Pallavi Phade
  • MJ-27012000-0 Profile Picture
    105 on at
    So Yun Zhu..
     
    I tried this but still not successful...
     
    These are the problems messages...
     
     
    reportextension 50100 CustomerStatementReportExt extends "Standard Statement"
    {
        dataset
        {
            modify(DtldCustLedgEntries)
            {
                column(PostedSalesInvExternalNo; PostedSalesInvExternalNo)
                {
                    Caption = 'Posted Sales Invoice - External Document No.';
                }
     
                trigger OnAfterGetRecord()
                begin
                    PostedSalesInvExternalNo := '';
     
                    if DtldCustLedgEntries."Document Type" = DtldCustLedgEntries."Document Type"::Invoice then begin
                        if PostedSalesInvoice.Get(DtldCustLedgEntries."Document No.") then
                            PostedSalesInvExternalNo := PostedSalesInvoice."External Document No.";
                    end;
                end;
            }
        }
        var
            PostedSalesInvoice: Record "Posted Sales Invoice";
            PostedSalesInvExternalNo: Text[100];
     
    }
  • Suggested answer
    YUN ZHU Profile Picture
    101,600 Super User 2026 Season 1 on at
    You don't seem to know how to write a Report Extension...
    Sorry I haven't tested the code below, but it compiles fine.
    reportextension 50100 CustomerStatementReportExt extends "Standard Statement"
    {
        dataset
        {
            add(DtldCustLedgEntries)
            {
                column(PostedSalesInvExternalNo; PostedSalesInvExternalNo)
                {
                    Caption = 'Posted Sales Invoice - External Document No.';
                }
            }
            modify(DtldCustLedgEntries)
            {
                trigger OnAfterAfterGetRecord()
                begin
                    PostedSalesInvExternalNo := '';
    
                    if DtldCustLedgEntries."Document Type" = DtldCustLedgEntries."Document Type"::Invoice then begin
                        if PostedSalesInvoice.Get(DtldCustLedgEntries."Document No.") then
                            PostedSalesInvExternalNo := PostedSalesInvoice."External Document No.";
                    end;
                end;
            }
        }
    
        var
            PostedSalesInvoice: Record "Sales Invoice Header";
            PostedSalesInvExternalNo: Text[100];
    
    }
     
    Thanks.
    ZHU
  • MJ-27012000-0 Profile Picture
    105 on at
    YUN ZHU
     
    I have done report extension. Perhaps as I did not include the line for the RDLClayout. Not sure how you got it to compile as I get an error on this line...
     
                column(PostedSalesInvExternalNo; PostedSalesInvExternalNo)
     
    reportextension 50100 CustomerStatementReportExt extends "Standard Statement"
    {
        RDLCLayout = './Statement_W_ExtDoc.rdlc';
        dataset
     
        {
            modify(DtldCustLedgEntries)
            {
                column(PostedSalesInvExternalNo; PostedSalesInvExternalNo)
                {
                    Caption = 'Posted Sales Invoice - External Document No.';
                }
     
                trigger OnAfterGetRecord()
                begin
                    PostedSalesInvExternalNo := '';
     
                    if DtldCustLedgEntries."Document Type" = DtldCustLedgEntries."Document Type"::Invoice then begin
                        if PostedSalesInvoice.Get(DtldCustLedgEntries."Document No.") then
                            PostedSalesInvExternalNo := PostedSalesInvoice."External Document No.";
                    end;
                end;
            }
        }
        var
            PostedSalesInvoice: Record "Posted Sales Invoice";
            PostedSalesInvExternalNo: Text[100];
     
    }
     
     
  • Suggested answer
    Jeffrey Bulanadi Profile Picture
    9,121 Super User 2026 Season 1 on at

    Hi,

    Adding the External Document No. to the Customer Statement requires referencing the correct posted document source. The current logic in your report extension is pointing to SalesHeader, which only works for unposted sales orders. Since the Customer Statement is built on Detailed Cust. Ledg. Entries, you’ll need to pull from Sales Invoice Header or Sales Credit Memo Header, depending on the document type.

    Here’s a clean path forward:

     

    1. Update Your Variables
      Replace SalesHeader with SalesInvoiceHeader and optionally SalesCrMemoHeader:
      var
          SalesInvoiceHeader: Record "Sales Invoice Header";
          SalesCrMemoHeader: Record "Sales Cr. Memo Header";
          SalesOrderExternalNo: Text[100];
       
    2. Refactor Your Trigger Logic
      Check for posted invoices and credit memos:
      trigger OnAfterGetRecord()
      begin
          SalesOrderExternalNo := '';
          case DtldCustLedgEntries."Document Type" of
              DtldCustLedgEntries."Document Type"::Invoice:
                  if SalesInvoiceHeader.Get(DtldCustLedgEntries."Document No.") then
                      SalesOrderExternalNo := SalesInvoiceHeader."External Document No.";
              DtldCustLedgEntries."Document Type"::"Credit Memo":
                  if SalesCrMemoHeader.Get(DtldCustLedgEntries."Document No.") then
                      SalesOrderExternalNo := SalesCrMemoHeader."External Document No.";
          end;
      end;
       
    3. Confirm Layout Binding
      Make sure your RDLC or Word layout includes the new field. If you're using Word, regenerate the layout to refresh the dataset bindings.
       
    4. Optional: Handle Unposted Orders
      If you truly need to show External Document No. from unposted Sales Orders (rare in statements), you’ll need to customize the report to include Sales Header records and join them manually — but this breaks standard posting logic and is not recommended.
       

    Helpful Reference
    Enter External Document Numbers – Microsoft Learn
    Community thread: External Doc No. in Statement
    Set External Document No. as Mandatory – Yun Zhu


    If you find this helpful, feel free to mark this as the suggested or verified answer.

    Cheers
    Jeffrey

  • Suggested answer
    YUN ZHU Profile Picture
    101,600 Super User 2026 Season 1 on at
    I tried again, and it published successfully without any problems.
     
    PS: Hope the following helps as well.
    How to add Media or MediaSet data type (Pictures) to a report
    Report extensibility (ReportExtension Object)
    Why are custom columns/fields added via Report Extension not found in standard layouts exported from Report Layouts page?
     
    Thanks
    ZHU

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 April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,382 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 1,625 Super User 2026 Season 1

#3
AndrewThomas81 Profile Picture

AndrewThomas81 1,376

Last 30 days Overall leaderboard

Featured topics

Microsoft Training Manuals

Product updates

Dynamics 365 release plans