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

Notifications

Announcements

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,384 Super User 2025 Season 2 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

News and Announcements

Season of Giving Solutions is Here!

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 1,651

#2
Khushbu Rajvi. Profile Picture

Khushbu Rajvi. 808 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 718 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans