Skip to main content

Notifications

Announcements

No record found.

Business Central forum
Suggested answer

trigger OnLookup() issue

Posted on by

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

  • Suggested answer
    Greg Enns Profile Picture
    Greg Enns 1,102 on at
    RE: trigger OnLookup() issue

    Your code seems good, so debugging is the first step and then digging into the application to see the details is after that. Sometimes, odd things get posted in the system that we do not expect to be there when we are developing.

    If you can use the debugger, then put a breakpoint on the Message(... line. When it gets there, hover your mouse over VendLedgEntry in the debugger. This should give you some info about the record it is finding (like the Entry No.). Then go into the application and take a look at that entry.

    If you cannot use the debugger, then add some more info to the Message--like EntryNo, Description, etc. of the VendLedgEntry.

  • Romryan Profile Picture
    Romryan on at
    RE: trigger OnLookup() issue

    Greg,

    Am getting a message with a blank document number which should be the case. I dont expect to get any message if the findfirst fails to filter any document but if findfirst filters a document then the message should popup showing the document.

  • Suggested answer
    YUN ZHU Profile Picture
    YUN ZHU 68,664 Super User 2024 Season 2 on at
    RE: trigger OnLookup() issue

    Hi, I tested the simplest case, and didn't encounter your problem. I think it is still a problem with your data. Please debug again.

    pastedimage1685490613644v2.png

    Hope this helps.

    Thanks.

    ZHU

  • Suggested answer
    Greg Enns Profile Picture
    Greg Enns 1,102 on at
    RE: trigger OnLookup() issue

    Sounds like you need to run the debugger. Your code looks correct, so the Message(...) should not execute unless both FindFirst are successful. If you are getting the Message, then you need to figure out what records it is finding that you are not expecting to be there. (i.e. Perhaps records with a blank document number.)

  • Romryan Profile Picture
    Romryan on at
    RE: trigger OnLookup() issue

    Hi,

    Any suggestion please?

  • Romryan Profile Picture
    Romryan on at
    RE: trigger OnLookup() issue

    Any suggestion please?

  • Romryan Profile Picture
    Romryan on at
    RE: trigger OnLookup() issue

    Inge M. Bruvik,

    It's a custom payment functionality whereby I am looking up an unapplied or partially applied vendor invoice.

  • Suggested answer
    Inge M. Bruvik Profile Picture
    Inge M. Bruvik 32,744 Moderator on at
    RE: trigger OnLookup() issue

    Are you simply just not trying to duplicate  functionality that is already in the system?

    Both from customer ledger entries and vendor ledger entries there is already functionality to show how entries are applied.

    And what field are you trying to do the lookup in?

    A standard field or a new field you have created?

Helpful resources

Quick Links

Dynamics 365 Community Update – Sep 16th

Welcome to the next edition of the Community Platform Update. This is a weekly…

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,339 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,177 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans