在任何表中搜索过程 Dynamics Business Central AL 中的任何字段

问题描述 投票:0回答:1

我正在努力优化 Dynamics Business Central 中的一些 AL 代码,我注意到在根据姓名或年龄等特定字段搜索记录时存在大量冗余代码。我想将其重构为一个更通用的函数,可以处理在任何表中搜索任何字段。

procedure findEmployeeNo(Name:Text[20]; Age:Integer): code[20]
begin
            // search by Name
            Employee.Reset();
            Employee.ChangeCompany(company.Name);
            Employee.Setrange("Name", Name);
            If Employee.FindFirst() then begin
                exit(Employee."No.")
            end;
            // search by Age
            Employee.Reset();
            Employee.Setrange("Age", Age);
            If Employee.FindFirst() then begin
                exit(Employee."No.")
            end;
    exit('');
end;
procedure findEmployeeNo(Name:Text[20]; Age:Integer): code[20]
var Employee: record Employee;
begin
            Employee := findFieldData('Employee', 'Name', Name)
            If Employee then begin
                exit(Employee."No.")
            end;
            Employee := findFieldData('Employee', 'Age', Age)
            If Employee then begin
                exit(Employee."No.")
            end;
    exit('');
end;
microsoft-dynamics navision dynamics-business-central dynamics-al businesscentral
1个回答
0
投票

您可以使用

RecRef/FieldRef
数据类型并记录
Field
表的变量来做到这一点。

但是为什么呢?这不会给你任何性能(可能相反),它会降低代码的可读性和使用静态棱镜等工具的可搜索性。

这种方法有很多缺点,但没有一个优点。恕我直言,不值得。

© www.soinside.com 2019 - 2024. All rights reserved.