Looping over records of table "Page Action" crash the application?

43 views Asked by At

I'm writing a code in AL to insert all actions of all pages in the system in a table, BUT somehow looping over Record "Page Action", In this code snippet I've just shown the name of the action but still running this procedure didn't show any action:

procedure populateActions()
var
    PageAction: Record "Page Action";
begin
    PageAction.Reset();
    if PageAction.FindSet() then begin
        repeat begin
            Message(PageAction.Name);
        end until PageAction.Next() = 0;
    end;
end;
1

There are 1 answers

1
ChristianBraeunlich On

Couldn't reproduce in my local docker container with an installed W1 22.4 (Platform 22.0.59833.0 + Application 22.4.59114.59867).

Received a message with all Page Action names: enter image description here

This is the code that was used:

page 50103 PopulateActionsList
{
    ApplicationArea = All;
    PageType = List;
    UsageCategory = Administration;

    actions {
        area(Processing) {
            action(ActionName)
            {
                ApplicationArea = All;

                trigger OnAction()
                begin
                    PopulateActions();
                end;
            }
        }
    }
    procedure PopulateActions()
    var
        PageAction: Record "Page Action";
        TypeHelper: Codeunit "Type Helper";
        TextBuilder: TextBuilder;
    begin
        if PageAction.FindSet() then begin
            repeat
                TextBuilder.Append(PageAction.Name + TypeHelper.CRLFSeparator());
            until PageAction.Next() = 0;
        end;
        Message(TextBuilder.ToText());
    end;
}

Note: if you want to display a lot of messages, even if only for debugging purposes (if you don't want to use the VSCode debugger), it is recommended to use the TextBuilder data type. Not only is it faster, but also allows you to open only one message dialog at the end of the process. I didn't run your code because it would use too many resources and takes too long for me to sit and wait to see results (if the web client doesn't crash by then).

I've modified your code so that only the first 5 records are shown in message dialogs. This way I'm also receiving the first 5 Page Action names: >empty<,Responsibilty Centers,Reports Layouts,Application Settings,Setup

    procedure populateActions()
    var
        PageAction: Record "Page Action";
        counter: Integer;
    begin
        PageAction.Reset();
        if PageAction.FindSet() then begin
            repeat begin
                Message(PageAction.Name);
                counter += 1;
            end until (PageAction.Next() = 0) or (counter = 5);
        end;
    end;

Please check the above code to see if it works for you. If it doesn't, could you verify that the table is not empty, e.g. by navigating to the table http://<hostname>/<environment>/?table=2000000143&tenant=default or by accessing the database server ...although I would be concerend if it's empty.