7

Today I noticed that if you set global variables in a report they get lost when using preview mode. It would be nice if there was a AL static code analysis warning when doing this with the hint that you should set AllowScheduling = false otherwise the global variables will not work for preview mode.


report 50100 "Item Label"

{

[..]


    procedure SetItemFilter(ItemFilter: Text)

    begin

        ItemFilterGlobal := ItemFilter;

    end;


    var

        ItemFilterGlobal: Text;

}


pageextension 50100 "Item List" extends "Item List"

{

    actions

    {

        addafter(CopyItem)

        {

            action("Item Label")

            {

                Caption = 'Item Label';

                ApplicationArea = All;

                Promoted = true;

                PromotedOnly = true;

                PromotedCategory = Process;

                Image = Report;


                trigger OnAction()

                var

                    Item: Record Item;

                    ItemLabel: Report "Item Label";

                    FirstRecord: Boolean;

                    ItemFilter: Text;

                begin

                    CurrPage.SetSelectionFilter(Item);

                    if Item.FindSet() then begin

                        FirstRecord := true;

                        repeat

                            if (FirstRecord = true) then begin

                                ItemFilter := Item."No.";

                                FirstRecord := false;

                            end else begin

                                ItemFilter := ItemFilter + '|' + Item."No.";

                            end;

                        until (Item.Next() = 0);

                    end;

                    ItemLabel.SetItemFilter(ItemFilter);

                    ItemLabel.Run();

                end;

            }

        }

    }

}

Category: Development
STATUS DETAILS
Needs Votes
Ideas Administrator

Thank you for this suggestion! Currently this is not on our roadmap. We are tracking this idea and if it gathers more votes and comments we will consider it in the future. Best regards, Business Central Team

Comments

D

This idea is related to the following changes that were added with BC 17:

https://docs.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/devenv-report-triggers?tabs=current%2Crdlc#modes


and to the design principles for designing reports:

https://docs.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/devenv-report-triggers?tabs=current%2Crdlc#multiplepreview

Category: Development