[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;
[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;
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,240 Super User 2024 Season 2
Martin Dráb 230,149 Most Valuable Professional
nmaenpaa 101,156