dynamics-business-centraldynamics-al

How do I pass variable information from one page to another part of the page AL


I'm trying to make a system where the "LineReferenceNumber" in the Incoming Lot Table is passed to the "Incoming Lot Lines Page", and from there, that number is used to set the "LotReference" field. I want to basically connect all the new lines I'm making to its proper incoming lot page and I'm not sure how to.

table 50101 "Incoming Lot Line Tables"
{
    Caption = 'Incoming Lot Line Tables';
    DataClassification = ToBeClassified;

    fields
    {
        field(1; "LineID"; Code[38])
        {
            Caption = 'LineID';
        }
        field(2; "LotReference"; Code[38])
        {
            Caption = 'LotReference';
        }
        field(3; "Metal Code"; Enum "MetalTypes")
        {
            Caption = 'Metal Code';
        }
        field(4; Weight; Decimal)
        {
            Caption = 'Weight';
            trigger OnValidate()
            var
                WeightConversion: Codeunit "Weight Conversion";
            begin
                Rec."OZ T C" := WeightConversion.ConvertToOZ(Rec.Weight, Rec."Weight Standard");
            end;
        }
        field(5; "Weight Standard"; Enum "Weight Standards")
        {
            Caption = 'Weight Standard';
            trigger OnValidate()
            var
                WeightConversion: Codeunit "Weight Conversion";
            begin
                Rec."OZ T C" := WeightConversion.ConvertToOZ(Rec.Weight, Rec."Weight Standard");
            end;
        }
        field(6; "OZ T C"; Decimal)
        {
            DecimalPlaces = 0 : 5;
            Editable = false;
        }
        field(7; "Live Price"; Decimal)
        {
            Caption = 'Live Price In USD';
        }
    }

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

    trigger OnInsert()
    var
        IDGeneration: Codeunit "ID Generation";
    begin
        if "LineID" = '' then
            "LineID" := IDGeneration.GenerateUniqueID();
    end;

}
table 50100 "Incoming Lot Table"
{
    Caption = 'Incoming Lot Table';
    DataClassification = ToBeClassified;
    fields
    {
        field(1; "Lot No."; Code[20])
        {
            Caption = 'Lot No.';
        }
        field(2; "Client Name"; Text[45])
        {
            Caption = 'Client Name';
        }
        field(3; "Client Phone No."; Text[10])
        {
            Caption = 'Client Phone No.';
        }
        field(4; "Sent To Lab"; Boolean)
        {
            Caption = 'Sent To Lab';
        }
        field(5; "OZ T"; Decimal)
        {

        }
        field(6; "LineReferenceNumber"; Code[38])
        {

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



    trigger OnInsert()
    var
        IDGeneration: Codeunit "ID Generation";
    begin
        if "LineReferenceNumber" = '' then
            "LineReferenceNumber" := IDGeneration.GenerateUniqueID()
    end;




}
page 50102 "Incoming Lot"
{
    PageType = Document;
    SourceTable = "Incoming Lot Table";
    ApplicationArea = All;
    Caption = 'Incoming Lot';
    UsageCategory = Documents;

    layout
    {
        area(Content)
        {
            group(General)
            {
                Caption = 'General';

                field("Lot No."; Rec."Lot No.")
                {
                    ToolTip = 'Specifies the value of the Lot No. field.', Comment = '%';
                    Editable = true;
                    NotBlank = true;
                }
                field("Client Name"; Rec."Client Name")
                {
                    ToolTip = 'Specifies the value of the Client Name field.', Comment = '%';
                    Editable = true;
                    NotBlank = true;
                }
                field("Client Phone No."; Rec."Client Phone No.")
                {
                    ToolTip = 'Specifies the value of the Client Phone No. field.', Comment = '%';
                    Editable = true;
                }
                field("Sent To Lab"; Rec."Sent To Lab")
                {
                    ToolTip = 'Specifies the value of the Sent To Lab field.', Comment = '%';
                    Editable = true;
                }
                field(SystemCreatedAt; Rec.SystemCreatedAt)
                {
                    ToolTip = 'Specifies the value of the SystemCreatedAt field.', Comment = '%';
                    Editable = true;
                }
            }
            group("Lot Information")
            {
                part(Lines; "Incoming Lot Lines")
                {
                    ApplicationArea = All;
                    SubPageLink = "LotReference" = FIELD("LineReferenceNumber");
                }
            }
        }
    }

    actions
    {
        area(Processing)
        {
            action("Delete Data")
            {
                Caption = 'Delete All Lots';
                ApplicationArea = All;
                trigger OnAction()
                begin
                    DeleteAllLots();
                end;
            }
            action("Upload Lot")
            {
                Caption = 'Upload Lot';
                ApplicationArea = All;
                trigger OnAction()
                begin
                    UploadLot();
                end;
            }
        }
    }

    procedure DeleteAllLots()
    var
        IncomingLotRec: Record "Incoming Lot Table";
    begin
        IncomingLotRec.DeleteAll();
        Message('All lots have been deleted.');
    end;

    procedure UploadLot()
    var
        IncomingLotRec: Record "Incoming Lot Table";
    begin
        IncomingLotRec.Init();
        IncomingLotRec."Client Name" := Rec."Client Name";
        IncomingLotRec."Client Phone No." := Rec."Client Phone No.";
        IncomingLotRec."Sent To Lab" := Rec."Sent To Lab";
        IncomingLotRec."LineReferenceNumber" := Rec."LineReferenceNumber";
        IncomingLotRec.Insert(false, true);
    end;
}
page 50124 "Incoming Lot Lines"
{
    PageType = ListPart;
    SourceTable = "Incoming Lot Line Tables";
    ApplicationArea = All;
    Editable = true;

    layout
    {
        area(Content)
        {
            repeater(Group)
            {
                field("Metal Code"; Rec."Metal Code")
                {
                    ApplicationArea = All;
                    Editable = true;
                }
                field("Weight Standard"; Rec."Weight Standard")
                {
                    ApplicationArea = All;
                }
                field("Weight"; Rec."Weight")
                {
                    ApplicationArea = All;
                }
                field("OZ T C"; Rec."OZ T C")
                {
                    ApplicationArea = All;
                    DecimalPlaces = 0 : 5;
                    Editable = false;
                }
            }
        }
    }

    trigger OnOpenPage()
    begin
        Rec.SetFilter("Metal Code", 'PLT');
    end;

}

Solution

  • You already set the SubPageLink on the Lines page part:

    SubPageLink = "LotReference" = FIELD("LineReferenceNumber");
    

    This filter is stored in a FilterGroup in which the filters are not visible by default. However you can change the currently selected FilterGroup to be able to work with the filters set by SubPageLink.

    On your subpage (Incoming Lot Lines) you then retrieve the value of the filter of LotReference:

    trigger OnOpenPage()
    var
        LotReferenceFilter: Text;
    begin
        Rec.FilterGroup(4);
        LotReferenceFilter := Rec.GetFilter(LotReference);
        Rec.FilterGroup(0);
    end;
    

    Two things to note:

    1. You might need to use another trigger than OnOpenPage to get the desired result.
    2. It is very important to reset the FilterGroup back to 0!

    You can read more about FilterGroups in the documentation.