问题描述
我正在尝试在 Visual Studio Code 中使用 SetAscending 用于商业中心销售订单列表页面。它可以将销售订单设置为“No”。字段降序但是它不会将滚动条重置到页面顶部。我试过将它添加到多个地方,它对页面进行排序,但没有滚动条更新。我可能会遗漏什么代码?
我已将其添加到的地方: 销售订单列表页面扩展 - OnAfterGetRecord 和 OnAfterGetCurrRecord 销售订单列表页面事件 - OnopenPageEvent、OnAfterGetRecordEvent 和 OnAfterGetCurrRecordEvent
trigger OnAfterGetCurrRecord()
begin
rec.SetCurrentKey("Document Type","No.");
rec.SetAscending("No.",false);
end
解决方法
您必须告诉页面导航到新的第一条记录。
在 OnOpenPage 触发器中,您执行以下操作:
Rec.SetCurrentKey("Document Type","No.");
Rec.SetAscending("No.",false);
if Rec.FindSet() then; // use if-then to avoid error if there are no records within the filter
,
您有 3 种方法可以用作 FIND
FindFirst
= 查找过滤器的第一次出现
Findlast
= 查找过滤器的最后一次出现
FindSet
= 查找过滤器的一组出现次数
您可以将它们全部与 repeat
和 until
语句一起使用来循环记录。
FindFirst
和 FindSet
的 Repeat
和 Until
之间的区别在于 FindSet
找到一组寄存器而 FindFirst
只找到一个所以 FindSet
它的性能更高。
对于你的情况 您需要修改属性sourceTableView。这是一个页面属性。 FindSet 用于页面列表中非 DataSourceTable 的变量。
在表中创建一个键,然后将此键放入页面的 sourceTableView 属性中。
,这对我有用。由于这是 Business Central 中的标准列表页面,因此我无法修改 SourceTableView。我不得不使用两个触发器来首先排序,然后将光标移动到列表的顶部。
trigger OnAfterGetRecord()
begin
rec.SetCurrentKey("Document Type","No.");
rec.SetAscending("No.",false);
end;
trigger OnOpenPage()
begin
rec.FindLast();
end;