Business Central:了解是否安装了扩展



在Business Central中,我希望根据是否安装了第三方扩展来启用/禁用页面扩展中的字段。我不想依赖第三方延期,因为大多数时候它不会出现,我们的延期也不依赖它。

有人知道如果一个扩展作为依赖项包含在app.json中,但在运行时没有安装,会发生什么吗?它安装在开发环境中,但不安装在运行时。我的假设是它将无法安装我的扩展。

对于我试图做的,第三方扩展数据将不必更新,但我想阅读它。

有没有办法确定是否安装了第三方扩展?

您可以使用以下命令:

[Ok := ] NavApp.GetModuleInfo(AppId: Guid, var Info: ModuleInfo)

来源:微软文档

如果未安装提供的AppId,它将返回false,否则,您将在info变量中获得有关已安装应用的所有信息。

一种选择是尝试打开一个已知属于另一个扩展的表。

如果另一个表不存在,RecordRef.Open(TableNum(将出错。

不幸的是,RecordRef.Open((没有返回类似于布尔值的值,例如Record.Get((,所以我们不能只做If RecordRef.Open()来测试它是否成功。

因此,您需要的是像以下这样的函数,作为"Try函数",它将在错误时返回"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"消息,只是,如果另一个扩展存在,请用你想做的任何事情替换第一条消息

如果另一个扩展名在客户的对象范围内,请小心,如果是这样,您可能需要检查该表是否确实是您期望的表!

您需要使用虚拟表AllObj来确定您要查找的表是否存在:

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获取所需字段的值。

最新更新