Skip to main content
Business Central forum
Answered

Lookup from previous record issue AL

editSubscribe (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 20,984 Super User 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 960 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,180 Super User 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,180 Super User 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 20,984 Super User 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.

Helpful resources

Quick Links

What Motivates a Super User?

We know many of you visit the Dynamics 365 Community and Power Platform…

Demystifying Copilot with Georg Glantschnig…

Industry experts answer burning questions directly from our amazing Community…

Setting Up Knowledge Sources for Copilot…

Look at how configuring a comprehensive knowledge base is crucial…

Leaderboard

#1
Andre Arnaud de Calavon Profile Picture

Andre Arnaud de Cal... 283,066 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 222,585 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,138

Product updates

Dynamics 365 release plans