Skip to main content

Notifications

Small and medium business | Business Central, N...
Answered

How add only unique value in External Doc field in Sales order?

Posted on by 221

Hello Experts

in sales Order page there is Field External Document No. if we tried to enter value in page  that already added and preseent in sales header table means if this field already have value in table Sales Header it should not allow same value to be entered I am unaware how to achive  cah you please help me i tried following code but stuck on validate of Ecternal DOc no. of page

thnaks in Advance Experts

field("Ext Doc No."; Rec."Ext Doc  No.")
            {
                ApplicationArea = All;
                //FieldPropertyName = FieldPropertyValue;
                trigger OnValidate()
                var
                    salesH: Record "Sales Header";
                begin
                    salesH.Reset;
                    SalesH.SetRange(salesH."No.", Rec."No.");
                    if SalesH.findfirst then begin
????


                    end;

                end;
            }
Categories:
  • DAnny3211 Profile Picture
    DAnny3211 9,272 Super User 2024 Season 1 on at
    RE: How add only unique value in External Doc field in Sales order?

    hi

    the external document number is not unique, you can associate it with multiple orders

    so the solution that Mohana proposes is correct

    DAniele

  • KasparsSemjonovs Profile Picture
    KasparsSemjonovs 3,924 Super User 2024 Season 2 on at
    RE: How add only unique value in External Doc field in Sales order?

    This is done already on Purchase Orders, so You can check the validation of that field, and create the same for Sales Documents.

  • Suggested answer
    Mohana Yadav Profile Picture
    Mohana Yadav 59,127 Super User 2024 Season 2 on at
    RE: How add only unique value in External Doc field in Sales order?

    Make sure that once you posted the Order fully then the Order will be deleted and in that case the system will check External Doc No. in the existing Orders and not the already posted (deleted) orders.

    If you want to check all existing and previous orders then use Customer Ledger Entries.

  • Verified answer
    Mohana Yadav Profile Picture
    Mohana Yadav 59,127 Super User 2024 Season 2 on at
    RE: How add only unique value in External Doc field in Sales order?

                       salesH.Reset;

                       SalesH.Setrange("Document Type", Rec."Document Type);

                       SalesH.Setfilter("No.",'<>%1',Rec."No.");

                       SalesH.SetRange("External Document No.", Rec.External Document No.);

                       if SalesH.findfirst then begin

                          Error('External Document No. %1 already used in document %2',Rec.External Document No.,SalesH."No.");

    Please fix if there are any compilation issues as I just typed the logic here.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

New! Quick response templatesâš¡

Save time with the new custom templates!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,219 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,056 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans