Skip to main content

Notifications

Announcements

No record found.

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

Lookup from previous record issue AL

(0) ShareShare
ReportReport
Posted on by

Dear All,

I have a field called Copy from No. and I have an OnLookUp trigger in it such that, if I pick the existing record, it should repopulate all other fields including the ones in the lines (list part).

Unfortunately, the lines are not populating. What’s the best way to do achieve this? Is there any other way? How do I link the header and the lines when I am looking up the previously entered record?

Warm Regards, 

RomRyan

  • Suggested answer
    Nitin Verma Profile Picture
    Nitin Verma 21,091 Super User 2024 Season 1 on at
    RE: Lookup from previous record issue AL

    Try this one

    L_ATb.Reset();

           L_ATb.setrange("No.");

           If Page.RunModal(Page::"L_A", L_ATb) = Action::LookupOK then begin

               Rec.Reset();

               Rec.SetRange("No.", Rec."No.");

               If Rec.FindFirst() then begin

                   Rec."Copy From No." := L_ATb."No.";

                   Rec."Audit Quarter" := L_ATb."Audit Quarter";

                   Rec."Audit Year" := L_ATb."Audit Year";

                   Rec.Department := L_ATb.Department;

                   Rec.Region := L_ATb.Region;

                   Rec."Posting Date" := L_ATb."Posting Date";

                   rec.modify;

               end;

               LineNo := 10000;

               L.Reset();

               LL.SetRange("No.", L_ATb."No.");

               If LL.FindSet() then

                   repeat

                       ll2.init;

                       ll2."No." := L_ATb."No.";

                       LL2."Line No." := LineNo;

                       LL2.Report := LL.Report;

                       LL2."Report Des" := LL."Report Des";

                       ll2.insert;

                   until LL.Next() = 0;

  • Romryan Profile Picture
    Romryan on at
    RE: Lookup from previous record issue AL

    Pankaj,

     RECHeaderTable has no Report and "Report Des" fields. These fields are in the lines table and just like the header table is reading from the existing record, the line table should do the same and I can have more than one lines.

    So still it hasn't worked.

  • Suggested answer
    pankaj.k Profile Picture
    pankaj.k 962 on at
    RE: Lookup from previous record issue AL

    Hi Romryan,

    you need to comment your code for the insert line level data.

    add below code on your Line Page OnInsertRecord Triger so whenever you create new line below code will add While Line Insert on Line Page.

        trigger OnInsertRecord()
        var
            RECHEader:REcord RECHeaderTable;
        begin
            RECHeaderTable.Reset();
            RECHeaderTable.SetRange("No.", LL."No.");
            If RECHeaderTable.Findfirst() then            
                LL.Report := RECHeaderTable.Report;
                LL."Report Des" := RECHeaderTable."Report Des";          

        end;
  • Suggested answer
    DAnny3211 Profile Picture
    DAnny3211 9,272 Super User 2024 Season 1 on at
    RE: Lookup from previous record issue AL

    hi

    but it seems to me that rec.modify and ll.modify are missing?

    although I don't understand LL2. "Line No." where you value it

    DAniele

  • Romryan Profile Picture
    Romryan on at
    RE: Lookup from previous record issue AL

    la.png

    The highlighted field in yellow is the lookup field. When I enter a new record, I need to use the field copy from No LookUp the existing one so that I can populate the rest of fields including the lines from copy from no lookup.

    Here is the code

    field("Copy From No."; Rec."Copy From No.")
    {
    ApplicationArea = All;
    ToolTip = 'Specifies the value of the Copy From No. field.';

    trigger OnLookup(var Text: Text): Boolean
    var

    LAList: Page "L_A";
    L_ATb: Record LTable;
    LL: Record LChecklist;
    LL2: Record LChecklist;
    LineNo: Integer;


    begin
    L_ATb.Reset();
    If Page.RunModal(Page::"L_A", L_ATb) = Action::LookupOK then
    Rec.Reset();
    Rec.SetRange("No.", Rec."No.");
    If Rec.FindFirst() then
    Rec."Copy From No." := L_ATb."No.";
    Rec."Audit Quarter" := L_ATb."Audit Quarter";
    Rec."Audit Year" := L_ATb."Audit Year";
    Rec.Department := L_ATb.Department;
    Rec.Region := L_ATb.Region;
    Rec."Posting Date" := L_ATb."Posting Date";

    LL.Reset();
    LL.SetRange("No.", L_ATb."No.");
    LL.SetRange("Line No.", LL2."Line No.");
    If LL.FindSet() then
    repeat
    If LL.FindFirst() then
    LL."Line No." := LineNo;
    LL.Report := LL.Report;
    LL."Report Des" := LL."Report Des";

    until LL.Next() = 0;

    end;

    }

  • Suggested answer
    DAnny3211 Profile Picture
    DAnny3211 9,272 Super User 2024 Season 1 on at
    RE: Lookup from previous record issue AL

    hi

    is not very clear:

    correct me if I am wrong:

    you would like to value a field in a row with the number of another row from which to copy data.

    for this you need to do a development

    but if you send us your code, maybe we can give you a few more hints.

    DAniele

  • Suggested answer
    Nitin Verma Profile Picture
    Nitin Verma 21,091 Super User 2024 Season 1 on at
    RE: Lookup from previous record issue AL

    Hi,

    The requirement is not much clear, can you please put some screen shot and what you did till now to achieve this share the code in text format.

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!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,445 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans