业务中心:知道是否安装了扩展
Business Central: know if an extension is installed
在 Business Central 中,我想根据是否安装了第 3 方扩展来启用/禁用页面扩展中的字段。我不想依赖这个第 3 方扩展,因为大多数时候它不会存在,我们的扩展也不依赖它。
有人知道如果扩展作为依赖项包含在 app.json 中但在运行时未安装会发生什么情况吗?它安装在开发环境中,但不安装在运行时。我的假设是它会导致我的扩展安装失败。
对于我正在尝试做的事情,第 3 方扩展数据将不必更新,但我想阅读它。
有没有办法确定是否安装了第 3 方扩展?
一个选择是尝试打开一个已知属于另一个扩展的 table。
RecordRef.Open(TableNum) 如果另一个 table 不存在就会报错。
不幸的是 RecordRef.Open() 没有 return 布尔值,例如Record.Get(),所以我们不能只做If RecordRef.Open()
来测试它是否成功。
因此你需要的是一个像下面这样的函数,它是一个 'Try Function' 将 return 一个 'false' 错误,而不是实际抛出错误并停止。
[TryFunction]
procedure CheckTableExists(reference: integer)
var
TryRecord: RecordRef;
begin
TryRecord.open(reference)
end;
然后你可以这样做,例如
trigger OnAction();
var
CheckOtherExtensionMgt: Codeunit "CheckOtherExtensionMgt";
begin
if CheckOtherExtensionMgt.CheckTableExists(66666) then
Message('66666 Exists'); //Do something if the other extension does exist
if CheckOtherExtensionMgt.CheckTableExists(27) then
Message('27 Exists'); //Prove that processing continues even if the other extension doesn't exist
end;
在我的环境中处理此操作时,我收到“27 Exists”消息,如果存在其他扩展,请将第一条消息替换为您想要执行的任何操作
请注意其他扩展名是否在客户的对象范围内,如果是这样,您可能需要检查 table 是否确实是您所期望的!
您需要使用虚拟 table AllObj
来确定您要查找的 table 是否存在:
local procedure GetValueWithoutDependency()
var
AllObj: Record AllObj;
RecRef: RecordRef;
begin
AllObj.SetRange("App Package ID", [GUID of the other extension]);
AllObj.SetRange("Object ID", [ID of the table in the other extension]);
if not AllObj.FindFirst() then
exit; // The table does not exist
RecRef.Open(AllObj."Object ID"); // Won't fail because we know the table is there
// Find your record
// Get the field value using FieldRef
end;
打开 RecordRef
后,设置过滤器以查找所需记录,然后使用 FieldRef
获取所需字段的值。
您可以使用命令:
[Ok := ] NavApp.GetModuleInfo(AppId: Guid, var Info: ModuleInfo)
如果未安装提供的 AppId,它将 return 为 false,否则,您将在信息变量中获得有关已安装应用的所有信息。
在 Business Central 中,我想根据是否安装了第 3 方扩展来启用/禁用页面扩展中的字段。我不想依赖这个第 3 方扩展,因为大多数时候它不会存在,我们的扩展也不依赖它。
有人知道如果扩展作为依赖项包含在 app.json 中但在运行时未安装会发生什么情况吗?它安装在开发环境中,但不安装在运行时。我的假设是它会导致我的扩展安装失败。
对于我正在尝试做的事情,第 3 方扩展数据将不必更新,但我想阅读它。
有没有办法确定是否安装了第 3 方扩展?
一个选择是尝试打开一个已知属于另一个扩展的 table。
RecordRef.Open(TableNum) 如果另一个 table 不存在就会报错。
不幸的是 RecordRef.Open() 没有 return 布尔值,例如Record.Get(),所以我们不能只做If RecordRef.Open()
来测试它是否成功。
因此你需要的是一个像下面这样的函数,它是一个 'Try Function' 将 return 一个 'false' 错误,而不是实际抛出错误并停止。
[TryFunction]
procedure CheckTableExists(reference: integer)
var
TryRecord: RecordRef;
begin
TryRecord.open(reference)
end;
然后你可以这样做,例如
trigger OnAction();
var
CheckOtherExtensionMgt: Codeunit "CheckOtherExtensionMgt";
begin
if CheckOtherExtensionMgt.CheckTableExists(66666) then
Message('66666 Exists'); //Do something if the other extension does exist
if CheckOtherExtensionMgt.CheckTableExists(27) then
Message('27 Exists'); //Prove that processing continues even if the other extension doesn't exist
end;
在我的环境中处理此操作时,我收到“27 Exists”消息,如果存在其他扩展,请将第一条消息替换为您想要执行的任何操作
请注意其他扩展名是否在客户的对象范围内,如果是这样,您可能需要检查 table 是否确实是您所期望的!
您需要使用虚拟 table AllObj
来确定您要查找的 table 是否存在:
local procedure GetValueWithoutDependency()
var
AllObj: Record AllObj;
RecRef: RecordRef;
begin
AllObj.SetRange("App Package ID", [GUID of the other extension]);
AllObj.SetRange("Object ID", [ID of the table in the other extension]);
if not AllObj.FindFirst() then
exit; // The table does not exist
RecRef.Open(AllObj."Object ID"); // Won't fail because we know the table is there
// Find your record
// Get the field value using FieldRef
end;
打开 RecordRef
后,设置过滤器以查找所需记录,然后使用 FieldRef
获取所需字段的值。
您可以使用命令:
[Ok := ] NavApp.GetModuleInfo(AppId: Guid, var Info: ModuleInfo)
如果未安装提供的 AppId,它将 return 为 false,否则,您将在信息变量中获得有关已安装应用的所有信息。