Dear all.
I have an issue with OnLookup trigger, once I lookup the document, the message in the code below is fired even if the FindFirst doesn't find any record and OfCourse with no value. I want to achieve a situation whereby if the filter findfirst find a record the message should be fired stating the document if no record is found then no message should be fired at all.
trigger OnLookup()
var
AppDoc, AppDoc2 : Code[20];
Pmt: Record "Payments";
VndrLdgr: Record "Vendor Ledger Entry";
begin
If Rec."No." <> '' then begin
Pmt.Reset();
Pmt.SetRange("Applies-to Doc. No.", Rec."Applies-to Doc. No.");
Pmt.SetFilter("No.", '<>%1', Rec."No.");
If Pmt.FindFirst() then begin
AppDoc2 := Pmt."No.";
VendLedgEntry.Reset();
VendLedgEntry.SetRange("Document No.", Rec."Applies-to Doc. No.");
If VendLedgEntry.FindFirst() then begin
Message('This invoice has been applied from Payment Document %1', AppDoc2)
end
else begin
exit;
end;
end;
end;
end