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

mysamzamysamza Posts: 45Member
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 move the Production Number that gets filled 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 selected, 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 a new record is created to make sure it is unique.

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.

Answers

  • ShaiHuludShaiHulud Posts: 77Member
    If you don't need to change "Production No." on individual lines at any point (always same as header), you could make it into a FlowField on the lines. Something along the lines of
    FieldClass = FlowField;
    CalcFormula = Lookup("Production Time Log Header"."Production No." WHERE (Entry No.=FIELD(Entry No.)));
    Editable = false;
    
    Arturas Kulsinskas
    NaviLogic
Sign In or Register to comment.