kuhi
kuhi

Reputation: 699

How to fill a page part based on a temporary table in Business Central?

I'm adding a page part in Sales Orders, where I want to show tracking lines.

This is the page part in Sales Orders:

pageextension 63200 "Sales Order Ext" extends "Sales Order"//42
{
    layout
    {
        addafter("Shipping and Billing")
        {
            part(TrackingListPart; "Parcel Tracking ListPart")
            {
                ApplicationArea = All;
                Caption = 'Tracking Information';                
            }
        }
    }

    actions
    {
        addlast(Processing)
        {
            action(Tracking)
            {
                ApplicationArea = All;
                Promoted = true;
                PromotedCategory = Process;
                Image = Track;
                RunObject = Page "Parcel Tracking ListPart";

                trigger OnAction()
                var
                    TrackingList: Record "Parcel Tracking";
                begin
                    CurrPage.TrackingListPart.PAGE.FillTrackingData(Rec."No.");

                    Message('Tracking information added.');
                end;
            }
        }
    }
}

This is the temporary table which will hold the tracking lines creating right now sample data for testing:

table 63200 "Parcel Tracking"
{
    DataClassification = ToBeClassified;
    TableType = Temporary;

    fields
    {
        field(1; "Tracking No."; Code[50]) { }
        field(2; Description; Text[250]) { }
        field(3; "Carrier"; Code[20]) { }
        field(4; "Status"; Text[50]) { }
        field(5; "Last Update"; DateTime) { }
        field(6; "Related Document No."; Code[20]) { }
    }

    keys
    {
        key(PK; "Tracking No.", Description) { Clustered = true; }
    }

    procedure FillTrackingRows(DocumentNo: Code[20])
    begin
        Reset();
        DeleteAll();        

        "Tracking No." := '123456';
        "Carrier" := 'UPS';
        "Status" := 'In Transit';
        "Last Update" := CURRENTDATETIME;
        "Related Document No." := DocumentNo;
        Insert();

        "Tracking No." := '2131234';
        "Carrier" := 'GLS';
        "Status" := 'In Transit';
        "Last Update" := CURRENTDATETIME;
        "Related Document No." := DocumentNo;
        Insert();
    end;
}

And this is the page or listpart:

page 63200 "Parcel Tracking ListPart"
{
    PageType = ListPart;
    SourceTable = "Parcel Tracking";
    DeleteAllowed = false;
    InsertAllowed = false;
    ModifyAllowed = false;
    RefreshOnActivate = true;
    SourceTableTemporary = true;

    layout
    {
        area(content)
        {
            repeater(Group)
            {
                field("Tracking No."; Rec."Tracking No.") { }
                field(Carrier; Rec.Carrier) { }
                field(Status; Rec.Status) { }
                field("Related Document No."; Rec."Related Document No.") { }
                field("Last Update"; Rec."Last Update") { }
            }
        }
    }

    procedure FillTrackingData(DocumentNo: Code[20])
    var
        TrackingList: Record "Parcel Tracking";
    begin
        Rec.FillTrackingRows(DocumentNo);

        CurrPage.Update(false);
    end;
}

So, when I click the button, it doesn't add lines, and it maximizes the listpart:

enter image description here

It's acting weird... How should I fill the lines correctly?

EDIT:

I've removed the line RunObject = Page "Parcel Tracking ListPart"; so it doesn't maximize the page

Upvotes: 0

Views: 31

Answers (1)

kuhi
kuhi

Reputation: 699

The problem was here:

field("Tracking No."; Rec."Tracking No.") { }
field(Carrier; Rec.Carrier) { }
field(Status; Rec.Status) { }
field("Related Document No."; Rec."Related Document No.") { }
field("Last Update"; Rec."Last Update") { }

No ApplicationArea in those fields, so no fields were displayed.

Here is a simplified example for someone that could need it:

table 63200 "Parcel Tracking"
{
    DataClassification = ToBeClassified;
    TableType = Temporary;

    fields
    {
        field(1; "Tracking No."; Code[50]) { }
        field(2; Description; Text[250]) { }
        field(3; "Carrier"; Code[20]) { }
        field(4; "Status"; Text[50]) { }
        field(5; "Last Update"; DateTime) { }
        field(6; "Related Document No."; Code[20]) { }
    }

    keys
    {
        key(PK; "Tracking No.", Description) { Clustered = true; }
    }

    procedure FillTrackingRows(DocumentNo: Code[20])
    begin
        Reset();
        DeleteAll();        

        "Tracking No." := '123456';
        "Carrier" := 'UPS';
        "Status" := 'In Transit';
        "Last Update" := CURRENTDATETIME;
        "Related Document No." := DocumentNo;
        Insert();

        "Tracking No." := '2131234';
        "Carrier" := 'GLS';
        "Status" := 'In Transit';
        "Last Update" := CURRENTDATETIME;
        "Related Document No." := DocumentNo;
        Insert();
    end;
}

page 63200 "Parcel Tracking"
{
    PageType = List;
    SourceTable = "Parcel Tracking";
    DeleteAllowed = false;
    InsertAllowed = false;
    ModifyAllowed = false;
    SourceTableTemporary = true;

    layout
    {
        area(content)
        {
            repeater(General)
            {
                field("Tracking No."; Rec."Tracking No.") 
                {
                    ApplicationArea = All;
                }
                field(Carrier; Rec.Carrier) 
                {
                    ApplicationArea = All;
                }
                field(Status; Rec.Status) 
                {
                    ApplicationArea = All;
                }
                field("Related Document No."; Rec."Related Document No.") 
                {
                    ApplicationArea = All;
                }
                field("Last Update"; Rec."Last Update") 
                {
                    ApplicationArea = All;
                }
            }
        }
    }
}

pageextension 63200 "Sales Order Ext" extends "Sales Order"//42
{
    actions
    {
        addlast(Processing)
        {
            action(Tracking)
            {
                ApplicationArea = All;
                Promoted = true;
                PromotedCategory = Process;
                Image = Track;

                trigger OnAction()
                var
                    ParcelTracking: Record "Parcel Tracking" temporary;
                begin
                    ParcelTracking.FillTrackingRows(Rec."No.");            

                    Page.Run(Page::"Parcel Tracking", ParcelTracking);
                end;
            }
        }
    }
}

And here the results:

enter image description here

Upvotes: 0

Related Questions