【问题标题】:Business Central: know if an extension is installedBusiness Central:知道是否安装了扩展
【发布时间】:2021-05-18 21:45:52
【问题描述】:

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

有谁知道如果扩展作为依赖项包含在 app.json 中但在运行时没有安装会发生什么?它安装在开发环境中,但未安装在运行时。我的假设是它会导致我的扩展安装失败。

对于我正在尝试做的事情,不需要更新第 3 方扩展数据,但我想阅读它。

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

【问题讨论】:

    标签: dynamics-business-central


    【解决方案1】:

    你可以使用命令:

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

    Source: Microsoft Docs

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

    【讨论】:

      【解决方案2】:

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

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

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

      因此,您需要一个类似以下的函数,作为“Try Function”,它会在错误时返回“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”消息,如果存在其他扩展程序,请将第一条消息替换为您想要执行的任何操作

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

      【讨论】:

        【解决方案3】:

        您需要使用虚拟表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 获取所需字段的值。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2012-07-20
          • 2016-10-07
          • 2014-11-02
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多