循环遍历表格 “Page Action” 的记录会导致应用程序崩溃吗?

huangapple go评论60阅读模式
英文:

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

问题

我正在使用AL编写代码,将系统中所有页面的所有操作插入到一个表中,但是以某种方式循环遍历“页面操作”记录。在这个代码片段中,我只显示了操作的名称,但是运行这个过程后没有显示任何操作:

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;
英文:

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

得分: 1

无法在我的本地Docker容器中重现,已安装W1 22.4(Platform 22.0.59833.0 + Application 22.4.59114.59867)

收到了一条包含所有页面操作名称的消息:循环遍历表格 “Page Action” 的记录会导致应用程序崩溃吗?

这是使用的代码:

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;
}

注意:如果您想显示很多消息,即使只是出于调试目的(如果您不想使用VSCode调试器),建议使用TextBuilder数据类型。它不仅更快,而且还允许您在过程结束时只打开一个消息对话框。我没有运行您的代码,因为它会使用太多资源,而且等待看结果需要太长时间(如果Web客户端在那时没有崩溃)。

我已经修改了您的代码,以便仅在消息对话框中显示前5条记录。这样我也收到了前5个页面操作名称>empty<,Responsibilty Centers,Reports Layouts,Application Settings,Setup

procedure populateActions()
var
    PageAction: Record &quot;Page Action&quot;;
    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;

请检查上述代码,看看是否适用于您。如果不起作用,请验证表格不是空的,例如通过导航到表格 http://&lt;hostname&gt;/&lt;environment&gt;/?table=2000000143&amp;tenant=default 或通过访问数据库服务器...尽管如果它是空的话,我会感到担忧。

英文:

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: 循环遍历表格 “Page Action” 的记录会导致应用程序崩溃吗?

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 &quot;Page Action&quot;;
        TypeHelper: Codeunit &quot;Type Helper&quot;;
        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 &quot;Page Action&quot;;
        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://&lt;hostname&gt;/&lt;environment&gt;/?table=2000000143&amp;tenant=default or by accessing the database server ...although I would be concerend if it's empty.

huangapple
  • 本文由 发表于 2023年7月23日 17:21:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/76747485.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定