AL, API, Application, AppVersion, BC14, BC17, Business Central, Code, Codeunit, DataVersion, Dependencies, Development Tips, Dynamics 365, Extension, GetCurrentModuleInfo, GetModuleInfo, How To, Information, Instalation & Configuration, Install, Name, on-premises, OnInstallAppPerCompany, Publisher, Tip & Tricks, Version.Create, Visual Studio Code, Wave 1, Wave 2

Extension Install Code

Extension install code is executed when:

  • An extension is installed for the first time.
  • An uninstalled version is installed again.

This gives you control to write different logics for first time installation of extension and reinstallations of uninstalled extensions.

This is achieved by defining Install Codeunit in your Extension.

First thing first:

  1. Subtype property of codeunit need to be set to Install
  2. OnInstallAppPerCompany trigger is triggered when the Extension is Installed first time or subsequent install of same version on Extension.
  3. DataVersion property one of the important properties which tells you what version of data that you’re dealing with.
  4. AppVersionDataVersionDependenciesIDName, and Publisher. These properties are encapsulated in a ModuleInfo data type. You can access these properties by using the NavApp.GetCurrentModuleInfo and NavApp.GetModuleInfo methods.
  5. If the DataVersion property equals Version.Create(0,0,0,0), then it’s the first time that the extension is installed because no data exists in the archive.

Sample codeunit can be similar to below:

codeunit <ID> “Name of Codeunit

{

    // Install Logic

    Subtype = Install;

    trigger OnInstallAppPerCompany();

    var

        myAppInfo: ModuleInfo;

    begin

        NavApp.GetCurrentModuleInfo(myAppInfo);

// Get info about the currently executing module

        if myAppInfo.DataVersion = Version.Create(0, 0, 0, 0) then

// A ‘DataVersion’ of 0.0.0.0 indicates a ‘fresh/new’ install

            HandleFreshInstall

        else

            HandleReinstall;

// If not a fresh install, then we are Reinstalling the same version of the extension

    end;

    local procedure HandleFreshInstall();

    begin

        // Logic to execute on first time this extension is ever installed for this tenant.

        // Some possible usages: – Initial data setup for use

    end;

    local procedure HandleReinstall();

    begin

        // Logic to execute on reinstalling the same version of this extension back on this tenant.

        // Some possible usages: – Data ‘patchup’ work, for example, detecting if new ‘base’

// records have been changed while you have been working ‘offline’.

    end;

}

Happy Learning.

Advertisement
Development Tips, How To

How to: Install a Windows Client Control Add-in Assembly

Microsoft Dynamics NAV Windows client control add-ins are provided in one or more Microsoft Framework .NET-based assemblies, which are .dll files. Control add-in assemblies must be installed on the following computers:

  • Computers that are running the Microsoft Dynamics NAV Windows client. Any Microsoft Dynamics NAV Windows client instance that will use the control add-ins, must be installed with the control add-in assemblies. Control add-in assemblies are not installed with the default Microsoft Dynamics NAV Windows client installation.
  • Computer that is running the Microsoft Dynamics NAV Development Environment. After a control add-in is installed, you use the development environment to register the control add-in the Client Add-in table in the Microsoft Dynamics NAV database and set it up on pages.

Optionally, if a control add-in has the same name as the assembly, you can install the assembly on the computer that is running Microsoft Dynamics NAV Server instead of the client computer.

To install control add-in assemblies on the Microsoft Dynamics NAV Windows client

  • If needed, install the Microsoft Dynamics NAV Windows client on the computer.
  • On the computer that is running the Microsoft Dynamics NAV Windows client, copy the assemblies that contain the control add-ins to the Add-ins folder of the Microsoft Dynamics NAV Windows client installation.
    • By default, the path of this folder is C:\Program Files (x86)\Microsoft Dynamics NAV\80\RoleTailored Client\Add-ins.

You can also include assemblies in a subfolder of the Add-ins folder. This can be useful if you have multiple assemblies and dependencies.

To install control add-in assemblies on the development environment computer

  • If needed, install the development environment on the computer.
  • On the computer that is running the development environment, create a folder named Add-in in the development environment installation folder.
    • By default, the path of this folder is C:\Program Files\Microsoft Dynamics NAV\80\Classic. If the Add-in folder already exists, then ignore this step.
  • Copy the assemblies that contain the control add-ins to the Add-ins folder.

You can also include assemblies in a subfolder of the Add-ins folder. This can be useful if you have multiple assemblies and dependencies.

Installing Control Add-ins on Microsoft Dynamics Server for Automatic Deployment

If a control add-in has the same name as the assembly, then you can install the assembly on computer that is running Microsoft Dynamics NAV Server. When an operation from the client requires the control add-in, Microsoft Dynamics NAV Server automatically deploys the assembly to a temporary folder on the client computer.

For example, if Microsoft Dynamics NAV Windows client opens a page that contains a control add-in, Microsoft Dynamics NAV Server will find the control add-in assembly by name in the Add-ins folder. Then, it deploys the assembly to the client computer in the %TEMP%\Microsoft Dynamics NAV\Add-Ins folder of the user who is running the client. The deployed assembly will be then be used whenever the page is opened.

Similarly, if the development environment requires a control add-in, for example, when you compile an object, then the control add-in assembly will be deployed by the Microsoft Dynamics NAV Server to the local temporary folder for the current user on the computer that is running the development environment.

To be deployed, an assembly must comply with the following Microsoft Dynamics NAV Server configuration settings: Chunk Size, Max Upload Size, and Prohibited File Types.

If the control add-in assembly is updated and its version number changes, Microsoft Dynamics NAV Server will deploy the updated assembly to the client computer the next time that the client requests the assembly. The updated assembly is put in a subfolder of the %TEMP%\Microsoft Dynamics NAV\Add-Ins folder, where the subfolder has the assembly’s version number as its name. This implementation means that you do have to remove the older versions of assemblies that are stored on the client computer.

Before Microsoft Dynamics NAV Server deploys an assembly to a client, the client looks for the assembly in the local Add-ins folder (for example, C:\Program Files (x86)\Microsoft Dynamics NAV\80\RoleTailored Client\Add-ins). If the assembly is not found, then the client will request the assembly from Microsoft Dynamics NAV Server.

To install the control add-in on Microsoft Dynamics NAV Server

  • On the computer that is running the Microsoft Dynamics NAV Server, copy the assembly that contains the control add-in to the Add-ins folder of the Microsoft Dynamics NAV Server installation.

By default, the path is C:\Program Files\Microsoft Dynamics NAV\80\Service\Add-ins.

Development Tips

How to create and install a test certificate for the Microsoft Dynamics NAV Server computer

To start with this exercise you need to first create certificate and certificate revocation list, if not yet created refer to previous post.

Previous Step Link- How to create a root CA and a private key file by using the makecert.exe utility

Previous Step Link- How to create certificate revocation list for the root certification authority

Let’s start with this exercise:

  • At the command prompt, type the following command:

makecert -sk NavServiceCert -iv RootNavServiceCA.pvk -n “CN=NavServiceCert” -ic RootNavServiceCA.cer -sr localmachine -ss my -sky exchange -pe NavServiceCert.cer

Note

This command specifies the subject’s certificate name as NavServiceCert. You need this certificate name when you configure the Microsoft Dynamics NAV Windows client or Microsoft Dynamics NAV Web Server components.

Certificate-13

  • When you are prompted, enter the password that you used to create the root CA.
  • Select the Trusted Root Certificate Authorities node, and then refresh the snap-in.

You now have the NavServiceCert.cer certificate file in your temporary folder. The certificate is installed under the Personal node in the Certificates Snap-in.

Certificate-14
In next step we will now grant access to the certificate’s private key to the service account on computer running Microsoft Dynamics NAV Server.

Next Step Link- How to grant access to the certificate’s private key to the service account for the Microsoft Dynamics NAV Server computer