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

Announcements

News and Announcements icon
Community site session details

Community site session details

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

External Document No Validation

(1) ShareShare
ReportReport
Posted on by 30
Hi,
I have added bit of code to validate the external document No on Sales Order. The current function detects if a duplicate External Doc number is entered on Sales Order and errors, user can’t continue with the order until a unique External Doc Number is entered.
I want to slightly amend this so only a warning message pops up if a user enters a duplicate External Doc Number, and they still can continue with the order. Can someone please help with this.
Here is My Code
[EventSubscriber(ObjectType::Table, Database::"Sales Header", 'OnAfterValidateEvent', 'External Document No.', false, false)]
    procedure CheckForDuplicatedExternalDocumentNo(var Rec: Record "Sales Header"; var xRec: Record "Sales Header"; CurrFieldNo: Integer)
    var
        SalesHeaderRec: Record "Sales Header";
        WKText001: Label 'External Document No. %1 already exist on %2 %3';
        WKText002: Label 'External Document No. %1 already exist on %2 %3';
        DocumentType: Label 'Sales %1';
        Archive: Label 'Archive';
        SalesDocument: Text;
    begin
        SalesHeaderRec.Reset();
        SalesHeaderRec.SetCurrentKey("External Document No.");
        SalesHeaderRec.SetRange(SalesHeaderRec."External Document No.", Rec."External Document No.");
        if SalesHeaderRec.Find('-') then begin
        if SalesHeaderRec."Sell-to Customer No." = Rec."Sell-to Customer No." then begin
            SalesDocument := StrSubstNo(DocumentType, SalesHeaderRec."Document Type");
            Error(WKText001, Rec."External Document No.", SalesDocument, SalesHeaderRec."No.");  // need to show a warning message instead of throwing an error 
        end;
     
    end;
I have the same question (0)
  • Verified answer
    Saurav.Dhyani Profile Picture
    14,419 User Group Leader on at
    Hi,
     
    Which localization you are using. I don't see code to check duplicate external document No. in Sales order.
     
    if it's a code that you have written and would like to modify, try with below code.
     
       [EventSubscriber(ObjectType::Table, Database::"Sales Header", 'OnAfterValidateEvent', 'External Document No.', false, false)]
        procedure CheckForDuplicatedExternalDocumentNo(var Rec: Record "Sales Header"; var xRec: Record "Sales Header"; CurrFieldNo: Integer)
        var
            SalesHeaderRec: Record "Sales Header";
            WKText001: Label 'External Document No. %1 already exist on %2 %3';
            WKText002: Label 'External Document No. %1 already exist on %2 %3. Would Suggest you Update External Document No.?';
            DocumentType: Label 'Sales %1';
            Archive: Label 'Archive';
            SalesDocument: Text;
        begin
            SalesHeaderRec.Reset();
            SalesHeaderRec.SetCurrentKey("External Document No.");
            SalesHeaderRec.SetRange(SalesHeaderRec."External Document No.", Rec."External Document No.");
            if SalesHeaderRec.Find('-') then begin
                SalesDocument := StrSubstNo(DocumentType, SalesHeaderRec."Document Type");
                if SalesHeaderRec."Sell-to Customer No." = Rec."Sell-to Customer No." then
                    if Confirm(StrSubstNo(WKText002, Rec."External Document No.", SalesDocument, SalesHeaderRec."No.")) then;
            end;
        end;
     
     
    Regards,
    Saurav Dhyani

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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders

These are the community rock stars!

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 1,713 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 1,032 Super User 2026 Season 1

#3
Grigorios Mavrogeorgis Profile Picture

Grigorios Mavrogeorgis 914 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Microsoft Training Manuals

Product updates

Dynamics 365 release plans