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

External Document Number in Sales Order

(0) ShareShare
ReportReport
Posted on by 130

When we are not given the external Document No. we should not allow  to insert Sales lines in the sales order, I am attaching my code what I have tried but I did not get it and can you share me any example how we can do it.

 trigger OnAfterGetCurrRecord()
    var
        myInt: Integer;
        SalesLine: Record "Sales Line";
        Value1: Text[20];
        Text000: Label 'The external document No. have to be given';
    begin
        if Rec."External Document No." = '' then
            Rec.FieldError("External Document No.", Text000);


    end;
  • Verified answer
    YUN ZHU Profile Picture
    82,945 Super User 2025 Season 1 on at
    RE: External Document Number in Sales Order

    Hi, please try the following.

    pastedimage1651709828057v1.png

    tableextension 50109 MyExtension extends "Sales Line"
    {
        trigger OnBeforeInsert()
        var
            SalesHeader: Record "Sales Header";
            Text000: Label 'The external document No. have to be given';
        begin
            if SalesHeader.Get(SalesHeader."Document Type"::Order, Rec."Document No.") then
                if SalesHeader."External Document No." = '' then
                    Error(Text000);
        end;
    }

    Thanks.

    ZHU

  • Suggested answer
    tanya07 Profile Picture
    1,636 on at
    RE: External Document Number in Sales Order

    Hi,

    Please follow as below -

    [EventSubscriber(ObjectType::Codeunit, 414, 'OnBeforeReleaseSalesDoc', '', false, false)]

       local procedure MyProcedure(var SalesHeader: Record "Sales Header")

       begin

           SalesHeader.TestField(ExtDocNo);

       end;

    Thanks,

    Tanya Kharbanda

    Don't forget to help the community by verifying the answer if your question has been answered. It will let others know that the topic has a verified answer.

  • Suggested answer
    MahGah Profile Picture
    15,443 on at
    RE: External Document Number in Sales Order

    Hi

    Please see suggestions in this post

    community.dynamics.com/.../i-need-to-do-external-document-no-as-mandatory

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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

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

#1
Sohail Ahmed Profile Picture

Sohail Ahmed 686

#2
YUN ZHU Profile Picture

YUN ZHU 646 Super User 2025 Season 1

#3
Mansi Soni Profile Picture

Mansi Soni 495

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans