Microsoft Dynamics Business Central Development – Technical Deep Dive

As we discussed previously in our introductory blog post Business Central – A Modern Solution That Integrates Easily, Microsoft Business Central is an all in one solution with built-in business integration, providing a single comprehensive solution to meet the needs of your growing business. However, it also comes with some challenges, one challenge that was recently faced and overcome by the Xgrid team was unsupported functionalities in the AL language. However, Business Central allows for the development of extensions using .NET interoperability. As the name suggests, these extensions provide flexibility and scalability to the Business Central solution by allowing for extended and diverse functionalities.

How do Extensions for Dynamics NAV Work?

With NAV Extensions, you can add functionality without changing the standard solution from Microsoft. This has the obvious advantage that major NAV upgrade projects are no longer necessary. Once you are using Extensions, the customizations no longer represent a problem when upgrading to the latest version of the solution.

Extensions for Microsoft Dynamics follow a model where you define the functionality as an addition to existing objects. This is how extensions can modify objects to perform business operations. We can develop multiple extensions so that development concerns are isolated and modularized but there is still a limitation under which these extensions perform that is the challenge.

The Challenge

All the functionalities from Dynamics are inherited to extensions but what if a development use case needs certain functionalities that are beyond the scope of Dynamics?
Here comes the Add-In Development for Business Central to rescue. Which provides a clean way to integrate .NET Framework assemblies to Dynamics NAV Server. This opened a lot of possibilities and eventually helped us drive the development smoothly.

One of the many use cases we had was to leverage Microsoft Active Directory user permissions to perform File Operations (Create/Update/Delete) on a Shared Network Drive. There is no built-in support for Active Directory in Dynamics NAV so we used our home-made .NET assembly which encapsulated all the critical File Operations. The basic setup for such Add-In development is provided below for reference.

Add-In Development – Technical Deep Dive

You can take advantage of .NET Framework interoperability so that Dynamics NAV objects can interact with .NET Framework objects. In your extensions, you can reference .NET Framework assemblies and call their members directly from C/AL code.

For easier understanding, we will develop a custom .NET class library that exposes a single method `CreateFile` which writes `Base64` encoded file to a specified location. Example code is provided below:

Now once you have the compiled DLL available, it’s time for Dynamics NAV .NET Interoperability to play its part.

Integrating .NET interoperability consists of the following three steps which are discussed in detail below:

1. Declaring the Assembly

To integrate .NET interoperability, the AL compiler needs to be pointed to the custom .NET assemblies. By default, the AL compiler is only pointed to the location of the default .NET assemblies. You need to explore the `settings.json` file and add your assembly path.

After the reference directory is added in `settings.json` you must declare the type in a `dotnet` construct provided by AL Language, and then reference it from code using the DotNet Variable type.

2. Execute members from .NET Assembly

After `dotnet` reference is created in AL, It’s time we can utilize the functionalities provided by our home-made assembly. We now need to create a `codeunit` which exposes an AL procedure

3. Publishing the extension

You now have everything in place, Just build the extension and you are almost ready to deploy the extension to your production environment.

When publishing an extension, the server will recompile code and try to resolve all the references to external assemblies. The compilation will only succeed if the server can locate and load all the referenced assemblies and types. Therefore, it is recommended to keep the same path for custom assembly on the development and Production business central environments.

Key Takeaways

Dynamics Nav has been helping customers improve their businesses by providing valuable insights. At Xgrid, it helped us expand the existing functionality through customization by adding more functionality using business central extensions. Microsoft Dynamics has a variety of features to boost productivity and is a fast, easy to use, and reliable solution to improve the overall efficiency of the business. Microsoft Dynamics improved forecasting, scheduling, management, and scalability with all other integrated applications. 

With business logic in its DNA business central has made many businesses survive making it a broad and deep functionality that runs thousands of companies all over the globe. To evolve and progress all contemporary business models should shift towards Business Central’s up-to-date solutions.

Read more