Skip to main content

Notifications

Small and medium business | Business Central, N...
Suggested answer

Pass value from form (header) to subform (lines)

(0) ShareShare
ReportReport
Posted on by 350

I have a Header table;

table 50108 "Production Time Log Header"
{
    DataClassification = ToBeClassified;

    fields
    {
        field(50000; "Entry No"; Integer)
        {
            DataClassification = CustomerContent;
        }
        field(50002; "Production No."; Code[20])
        {
            DataClassification = ToBeClassified;


        }
        field(50003; "Total"; Decimal)
        {
            FieldClass = FlowField;
            CalcFormula = sum ("Production Time Log Lines"."Run Time" where("Production No." = field("Production No.")));
        }
     
    }

    keys
    {
        key(PK; "Entry No")
        {
            Clustered = true;
        }
    }

    var
        myInt: Integer;

    trigger OnInsert()
    var
        recPTLH: Record "Production Time Log Header";
    begin
        Clear(recPTLH);
        IF recPTLH.FindLast() then
            "Entry No" := recPTLH."Entry No" + 1
        else
            "Entry No" := 1;
    end;

}

and a Line table;

table 50113 "Production Time Log Lines"
{
    DataClassification = ToBeClassified;

    fields
    {
        field(50000; "Entry No"; Integer)
        {
            DataClassification = CustomerContent;
        }
        field(50001; "Line No."; Integer)
        {
            DataClassification = CustomerContent;
            Editable = false;
        }
        field(50002; "Production No."; Code[20])
        {
            DataClassification = CustomerContent;
            //   TableRelation = "Production Time Log Header"."Production No." where("Entry No" = field("Entry No"));
            //  ValidateTableRelation = true;

        }
         field(50003; "Process"; Code[20])
        {
            DataClassification = CustomerContent;
            TableRelation = "Work Center";
        }
        field(50012; "Run Time"; Decimal)
        {
            DataClassification = CustomerContent;
        }


    }


    keys
    {
        key(PK; "Entry No", "Line No.")
        {
            Clustered = true;

        }
        key(T; "Run Time")
        {
            MaintainSqlIndex = false;
            MaintainSiftIndex = true;
            SumIndexFields = "Run Time";
        }
    }

    var
        myInt: Integer;

    trigger OnInsert()
    begin

    end;

}

and a Header page;

page 50111 "Production Time Log Card"
{
    PageType = Document;
    ApplicationArea = All;
    UsageCategory = Administration;
    SourceTable = "Production Time Log Header";
    RefreshOnActivate = true;


    layout
    {
        area(Content)
        {
            group(General)
            {
                field("Entry No"; "Entry No")
                {
                    ApplicationArea = All;
                }
                field("Production No."; "Production No.")
                {
                    ApplicationArea = All;
                    TableRelation = "Production Order"."No.";
                }
                field(Total; Total)
                {
                    ApplicationArea = All;
                }
            }
            part(Line; "Production Time Log Subform")
            {

                Visible = true;
                ShowFilter = true;
                UpdatePropagation = Both;
                SubPageLink = "Entry No" = field("Entry No");

            }
        }
    }

 
}

and a Subform;

page 50112 "Production Time Log Subform"
{
    PageType = ListPart;
    ApplicationArea = All;
    UsageCategory = Administration;
    SourceTable = "Production Time Log Lines";
    AutoSplitKey = true;
    DelayedInsert = true;
    MultipleNewLines = true;


    layout
    {
        area(Content)
        {
            repeater(Line)
            {
                field(Process; Process)
                {
                    ApplicationArea = All;

                }
         
                field(Runtime; Runtime)
                {
                    ApplicationArea = All;
                    
                }
            }
        }
    }
    }

}

I am trying to copy the Production Number that gets entered up on the Header to the Lines. So when a new document is created, let's say with Production No. = 100, for the line items that user creates, for every line I would like to save 100 as well. I can get this moved from Header to Line if I keep Production No. as my Primary Key. And my case does not allow that, because for every header with production no 100 I can have multiple Lines posted. Hence I made Entry No as a kind of Document No for my table and increment it by 1 every time. Inshort, how do I get my Production No from header flow to my lines table? Thanks a lot in advance for the help! I have seen 36 and 37 and could not figure it out.

  • Suggested answer
    Stefano Demiliani Profile Picture
    Stefano Demiliani 37,162 Most Valuable Professional on at
    RE: Pass value from form (header) to subform (lines)

    Answered on the other forum. Set correctly the key on the Line table (Entry No, Production No, Line No) and all is working.

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

News and Announcements

Announcing Category Subscriptions!

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,359 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,370 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans