How can I reload current page with a temporary table records?

kuhikuhi Member Posts: 18
edited 2024-05-07 in NAV Tips & Tricks
I'm in page "Assembly Orders" 902 trying to filter out some records and display only the assembly orders that the user is allowed.
Basically, trying to populate a temporary table to reload the current page with the records of the temporary table:
pageextension 60008 "Assembly Orders PL" extends "Assembly Orders"//902
{
    trigger OnOpenPage()
    var
        AssemblyOrders: Page "Assembly Orders";
        OriginalHeader: Record "Assembly Header";
        AssemblyHeaderTemp: Record "Assembly Header" temporary;
    begin
        if not RunOnce then begin
            AssemblyHeaderTemp.Reset();
            AssemblyHeaderTemp.DeleteAll();
            OriginalHeader.SetRange("Document Type", Rec."Document Type"::Order);
            if OriginalHeader.FindSet() then
                repeat                                    
                    // Check if the No. Series have extra security
                    if LMEnsamblado.ImplicaSeguridad(OriginalHeader."No. Series") then begin
                        // If the No. Series has extra security, we check if the current user has rights
                        if LMEnsamblado.TienePermisosLM(OriginalHeader."Item No.") then begin                        
                            AssemblyHeaderTemp.Init();                            
                            AssemblyHeaderTemp.TransferFields(OriginalHeader);
                            AssemblyHeaderTemp.CalcFields(Comment);
                            AssemblyHeaderTemp.CalcFields("Reserved Quantity");
                            AssemblyHeaderTemp.CalcFields("Reserved Qty. (Base)");
                            AssemblyHeaderTemp.CalcFields("Assemble to Order");
                            AssemblyHeaderTemp.CalcFields("Rolled-up Assembly Cost");
                            AssemblyHeaderTemp.Insert();
                        end;
                    end;
                until OriginalHeader.Next() = 0;

            CurrPage.Close();
            AssemblyOrders.SetRecord(AssemblyHeaderTemp);
            AssemblyOrders.SetTableView(AssemblyHeaderTemp);
            AssemblyOrders.SetRunOnce();
            AssemblyOrders.Run();
            CurrPage.Update();
        end;
    end;

    procedure SetRunOnce()
    begin
        RunOnce := true
    end;

    var
        LMEnsamblado: Codeunit "LM Ensamblado";
        RunOnce: Boolean;
}

The standard page without customization returns 91 assembly orders. This customization also returns 91 assembly orders. So the view is not applied because debugging I can see that it's inserting the correct records to the temporary table.

How can I reload the current page with a temporary table view?

Thanks in advance :smile:

Answers

  • vaprogvaprog Member Posts: 1,141
    edited 2024-05-08
    Called like you do, the page uses the database table, not your temporary one. SetRecord sets the position, SetTableView transfers the view (Filters and sorting) but these are applied to to the pages Rec.

    You would need to call the page using
    Page.Run(PAGE::"Assembly Orders",AssemblyHeaderTemp)
    
    in order to run it on the temporary table. You can then replace
    if not RunOnce then
    
    by
    if not IsTemporary then
    

    Another, and in my opinion better approach was to filter the page, rather that to populate a temporary one.
    You could use an approach similar to the one Page 31 Item List uses for Item Attribute filtering, or even drop the temp table and filter on the fly. In essence you need to implement OnFindRecord and OnNextRecord for the page in such a way that it only finds or steps to records you want to show.
    Have a look at Filtering data on form using OnFindRecord and OnNextRecord to see how this can be done. Your condition on when to insert a record into the temp table above would go to the function ShowThisRecord there.
Sign In or Register to comment.