web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested Answer

Restricting List Page based on Filter on Openpage

(0) ShareShare
ReportReport
Posted on by 297

Hello,

I created a new List Page with the objective of listing items that need to be reorder based on Safety Stock Quantity - (Inventory + Quantity On Purchase Order) > 0

Page 60100 ItemReorderList

{
    PageType = list;
    UsageCategory = Lists;
    ApplicationArea = All;

    SourceTable = Item;

    Caption = 'Item Below Safety Level';

    layout
    {
        area(Content)
        {
            repeater(control)
            {
                field("No."; "No.")
                { ApplicationArea = All; }
                field(Description; Description)
                { ApplicationArea = All; }
                field(Inventory; Inventory)
                { ApplicationArea = All; }
                field("Qty. on Purch. Order"; "Qty. on Purch. Order")
                { ApplicationArea = All; }
                field("Safety Stock Quantity"; "Safety Stock Quantity")
                { ApplicationArea = All; }
                field("Suggested Reorder"; "Safety Stock Quantity" - (Inventory + "Qty. on Purch. Order"))
                { ApplicationArea = All; }
            }
        }

    }
    trigger OnOpenPage();
    begin
        SetFilter("Safety Stock Quantity", '>0');
    end;
}

I would like to filter based on the calculated field > Suggested Reorder but am aware that SetFilter can only be used on fields in table and not calculated field.

Any suggestions on work around?

Appreciate all comments.

Thank you

May

I have the same question (0)
  • Suggested answer
    ArturV Profile Picture
    225 on at

    Hello May,

    I'd suggest to have a page based on temporary table. Make sure that SourceTableTemporary = Yes.

    Have a function BuildSource and code like this:

    function BuildSource

    var

     Item : Record Item;

    BEGIN

     IF Item.FINDSET THEN

        REPEAT

          Item.CALCFIELDS(Inventory); // include all the flowfields into this statement, comma-separated

          IF Item."Safety Stock Quantity" - (Item.Inventory + Item."Quantity On Purchase Order") > 0 THEN BEGIN

             Rec := Item;

             Rec.INSERT;

           END;

        UNTIL Item.Next = 0;

    END;

    Then call BuildSource function from OnOpenPage trigger.

  • Tymay Profile Picture
    297 on at

    Thanks ArturV for your feedback.

    I used your guideline above to transform into below codes (I am very new to AL as such, may have errors in the coding)

    1. Create a new page for codeunit below

    --------------------------------------------

    codeunit 60100 "ReorderBuildSource"

    {

       trigger OnRun()

       begin

       end;

       procedure ReorderBuild()

       var

           Item: Record Item;

       begin

           If Item.FindSet then

               repeat

                   Item.CalcFields("No.");

                   Item.CalcFields(Description);

                   Item.CalcFields(Inventory);

                   Item.CalcFields("Qty. on Purch. Order");

                   Item.CalcFields("Safety Stock Quantity");

                   If Item."Safety Stock Quantity" - (Item.Inventory + Item."Qty. on Purch. Order") > 0

                       then begin

                       Item.insert;

                   end;

               Until Item.next = 0;

       end;

       var

           myInt: Integer;

    }

    I did not manage to add in the line

    Rec := Item;

    As i am not sure what the syntax should be.

    2. Revise the new list page to include SourceTableTemporary = true and call to the codeunit upon open page.

    --------------------------------------------

    page 60100 ItemReorderList

    {

       PageType = list;

       SourceTableTemporary = true;

       UsageCategory = Lists;

       ApplicationArea = All;

       SourceTable = Item;

       Caption = 'Item Below Safety Level';

       layout

       {

           area(Content)

           {

               repeater(control)

               {

                   field("No."; "No.")

                   { ApplicationArea = All; }

                   field(Description; Description)

                   { ApplicationArea = All; }

                   field(Inventory; Inventory)

                   { ApplicationArea = All; }

                   field("Qty. on Purch. Order"; "Qty. on Purch. Order")

                   { ApplicationArea = All; }

                   field("Safety Stock Quantity"; "Safety Stock Quantity")

                   { ApplicationArea = All; }

                   field("Suggested Reorder"; "Safety Stock Quantity" - (Inventory + "Qty. on Purch. Order"))

                   { ApplicationArea = All; }

               }

           }

       }

       trigger OnOpenPage();

       begin

           codeunit.run(60100);

       end;

    }

    As i am a new AL developer, i had been struggling on finding the right syntax for the advise you had given. Greatly appreciate if you can help me to review and suggest changes.

    I managed to publish but there arent any records displayed when displaying the window.

    Greatly appreciate  your help.

    Thanks,

    May

  • Suggested answer
    ArturV Profile Picture
    225 on at

    Good day, May

    There are few issues i see in your solution.

    First of all, in the OnOpenPage trigger you have this code:

    codeunit.run(60100);

    It won't work since in your codeunit 60100 you don't have any code in the OnRun trigger. You only have a function ReorderBuild. So you need to call this function, not codeunit.run

    The second thing and the reason why you cannot compile Rec := Item:

    You don't pass Item record from the page to codeunit function.  In my initial suggestion i was told to add a function to the page and it will work. If you decided to have a codeunit then you need to pass the record to your function ReorderBuild. Below you can find two objects i've implemented in C/AL. Hope this helps.

    OBJECT Codeunit 60100 ReorderBuildSource

    {

     OBJECT-PROPERTIES

     {

       Date=;

       Time=;

       Version List=;

     }

     PROPERTIES

     {

       OnRun=BEGIN

             END;

     }

     CODE

     {

       PROCEDURE BuildReoderList@2(VAR ReorderedItem@1000 : Record 27);

       VAR

         Item@1001 : Record 27;

       BEGIN

         IF Item.FINDSET THEN

           REPEAT

             Item.CALCFIELDS(Inventory,"Qty. on Purch. Order");

             IF Item."Safety Stock Quantity" - (Item.Inventory + Item."Qty. on Purch. Order") > 0 THEN BEGIN

               ReorderedItem := Item;

               ReorderedItem.INSERT;

             END;

           UNTIL Item.NEXT = 0;

       END;

       BEGIN

       END.

     }

    }

    OBJECT Page 60100 ItemReorderList

    {

     OBJECT-PROPERTIES

     {

       Date=;

       Time=;

       Version List=;

     }

     PROPERTIES

     {

       Editable=No;

       SourceTable=Table27;

       PageType=List;

       SourceTableTemporary=Yes;

       OnOpenPage=VAR

                    ReorderBuildSource@1000 : Codeunit 60100;

                  BEGIN

                    ReorderBuildSource.BuildReoderList(Rec);

                  END;

     }

     CONTROLS

     {

       { 1000000;0;Container ;

                   ContainerType=ContentArea }

       { 1000001;1;Group     ;

                   Name=Group;

                   GroupType=Repeater }

       { 5   ;2   ;Field     ;

                   SourceExpr="No.";

                   ImplicitType=Code20 }

       { 4   ;2   ;Field     ;

                   SourceExpr=Description;

                   ImplicitType=Text100 }

       { 3   ;2   ;Field     ;

                   SourceExpr=Inventory;

                   ImplicitType=Decimal }

       { 2   ;2   ;Field     ;

                   SourceExpr="Qty. on Purch. Order";

                   ImplicitType=Decimal }

       { 1   ;2   ;Field     ;

                   SourceExpr="Safety Stock Quantity";

                   ImplicitType=Decimal }

       { 6   ;2   ;Field     ;

                   Name=SuggestedReorder;

                   CaptionML=ENU=Suggested Reorder;

                   SourceExpr="Safety Stock Quantity" - Inventory + "Qty. on Purch. Order" }

     }

     CODE

     {

       BEGIN

       END.

     }

    }

  • Suggested answer
    Olister Rumao Profile Picture
    3,967 on at

    Hi,

    You can do this.
    First Create a Table say ItemsShortage and refresh this Table everytime you open the page.
    https://docs.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/devenv-table-object

    Create a Page with and add all the fields 
    https://docs.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/devenv-page-object 

    Create a procedure in the Page to refresh the data and call it on OnOpenPage trigger of the Page.

    procedure refreshtheshortagelist()

    var

    Rec_Items: Record Item;

    Rec_ItemsShortage : Record ItemsShortage; 

    begin

    CLEAR(Rec_Items);

    CLEAR(Rec_ItemsShortage );

    Rec_ItemsShortage.DELETEALL();

    IF Rec_Items.FINDSET THEN BEGIN

       REPEAT

        IF Rec_Items.Quantity < (Rec_Items.Safety Stock Quantity" - (Rec_Items.Inventory + Rec_Items."Qty. on Purch. Order")) THEN BEGIN

             Rec_ItemsShortage.No := Rec_Item.No;

             Rec_ItemsShortage.Description := Rec_Items.Description;

             Rec_Items.CALCFIELDS("Qty. on Purch. Order");

             Rec_ItemsShortage. "Qty. on Purch. Order" := Rec_Items."Qty. on Purch. Order";

             Rec_ItemsShortage."Safety Stock Quantity" := Rec_Items."Safety Stock Quantity";

             Rec_ItemsShortage."Suggested Reorder" := Rec_Items."Safety Stock Quantity" - (Rec_Items. Inventory +Rec_Items."Qty. on Purch. Order");

             Rec_ItemsShortage.INSERT;

       END;

       UNTIL Rec_Items.NEXT = 0;

    END;

    end;

    I hope this helps!

  • Tymay Profile Picture
    297 on at

    ArturV, Greatly appreciate your patience going through my code and your kind feedback.

    I had revise the code as below:

    codeunit 60100 "ReorderBuildSource"

    {

       trigger OnRun()

       begin

       end;

       PROCEDURE ReorderBuild(VAR ReorderedItem: Record Item);

       VAR

           Item: Record Item;

       BEGIN

           IF Item.FINDSET THEN

               REPEAT

                   Item.CALCFIELDS("Safety Stock Quantity");

                   IF Item."Safety Stock Quantity" - (Item.Inventory + Item."Qty. on Purch. Order") < 0 THEN BEGIN

                       ReorderedItem := Item;

                       ReorderedItem.INSERT;

                   END;

               UNTIL Item.NEXT = 0;

       END;

    }

    page 60100 ItemReorderList

    {

       PageType = list;

       SourceTable = Item;

       SourceTableTemporary = true;

       UsageCategory = Lists;

       ApplicationArea = All;

       Caption = 'Item Below Safety Level';

       layout

       {

           area(Content)

           {

               repeater(control)

               {

                   field("No."; "No.")

                   { ApplicationArea = All; }

                   field(Description; Description)

                   { ApplicationArea = All; }

                   field(Inventory; Inventory)

                   { ApplicationArea = All; }

                   field("Qty. on Purch. Order"; "Qty. on Purch. Order")

                   { ApplicationArea = All; }

                   field("Safety Stock Quantity"; "Safety Stock Quantity")

                   { ApplicationArea = All; }

                   field("Suggested Reorder"; "Safety Stock Quantity" - (Inventory + "Qty. on Purch. Order"))

                   { ApplicationArea = All; }

               }

           }

       }

       trigger OnOpenPage();

       var

           ReorderBuildSource: Codeunit "ReorderBuildSource";

       begin

           ReorderBuildSource.ReorderBuild(Rec);

       end;

    }

    If i were to add this line in the procedure

    Item.CALCFIELDS("Safety Stock Quantity");

    I would encounter message "The Safety Stock Quantity field in the Item table must be a FlowField." when i call this list page at BC.

    I tried commenting the statement

             //      Item.CALCFIELDS("Safety Stock Quantity");

    And only have the following statements

    IF Item."Safety Stock Quantity" - (Item.Inventory + Item."Qty. on Purch. Order") > 0 THEN BEGIN

                       ReorderedItem := Item;

                       ReorderedItem.INSERT;

                   END;

    It managed to get the records to the list page but the filteration is based on Safety Stock Quantity > 0 with the calculation where it minus out the Inventory and Qty on Purchase Order. I had tried changing to = 0 and i can see that it is taking up records where safety stock = 0.

    I would again appreciate your patience on reviewing the above and advise me on where i went wrong.

    Thanking you inadvance.

    May

  • Tymay Profile Picture
    297 on at

    Oh yeah... for your information, the fields Safety stock quantity is a normal field where user enter a value via the Item Page.

  • Tymay Profile Picture
    297 on at

    Thanks Olister for your kind recommendation. Will surely try that out.

  • Tymay Profile Picture
    297 on at

    I finally managed to get it working.

    Codes as below:

    codeunit 60100 "ReorderBuildSource"

    {

       trigger OnRun()

       begin

       end;

       PROCEDURE ReorderBuild(VAR ReorderedItem: Record Item);

       VAR

           Item: Record Item;

       BEGIN

           IF Item.FINDSET THEN

               REPEAT

                   Item.Calcfields(Inventory, "Qty. on Purch. Order");

                   IF (Item."Safety Stock Quantity" - (Item.Inventory + Item."Qty. on Purch. Order")) > 0 THEN BEGIN

                       ReorderedItem := Item;

                       ReorderedItem.INSERT;

                   END;

               UNTIL Item.NEXT = 0;

       END;

    Thank you for all input provided. Great appreciated.

  • Netjacker2097 Profile Picture
    286 on at

    Awesome! Just what I needed also thanks May Trang

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

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 3,229

#2
Jainam M. Kothari Profile Picture

Jainam M. Kothari 1,867 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 1,153 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans