How to create your first extension in Microsoft Dynamics NAV

Hi guys, today I am here with another interesting article which is about “How to create your extensions in Microsoft Dynamics NAV”. Extensions in Dynamics NAV is relatively a new concept but trust me, it is a cool thing.

So, the today’s agenda is

  • Introduction
  • Prerequisite
  • Demo

Introduction

Extension is a new approach of development in Dynamics NAV. It is introduced in Dynamics NAV 2016. The main idea behind extensions is to ship the customization without actually modifying the standard objects/code. This approach leads us to easy upgrade as we are only merging the code which is changed by Microsoft.

Extensions works on the top of Delta files. If you remember from the Upgrade process, Delta files are the files which are generated as a result of comparison i.e. comparison of Standard Object with the modified (customized) object. The same approach is used in extensions.

Before actual development, don’t forget to make the backup of your original database.

Prerequisite

  • Before moving ahead, the prerequisite of this walkthrough is you have fair idea of the concept of Events in Dynamics NAV. If you have miss that topic you can read about it here.
  • Basic knowledge of Powershell, as mostly process of extension can be done via PowerShell.
  • You must have the original (standard) database on the version you are working.
  • Delta files generated as a result of comparison of two or more text files so make sure you have the backup of NAV Standard Application Objects .txt format. If not, export them via NAV development environment.

Demo to create your first extension

  1. Make a backup of your database before doing any changes.
  2. Develop the changes you want to ship with your extensions.
    1. For example, I am adding the field say “Super Cool Customer” of type Boolean in the Customer table. Also, I am adding this field on Customer Card Page and Customer List Page. I am also creating a table 50000 say “Customer Comments” having fields “Customer No.” and “Comments” as shown in the screenshot:1234
  3. After implementing the required functionality, add the Upgrade Codeunit for your extension. It is mandatory to add this codeunit after MS Dynamics NAV 2016. This upgrade codeunit will contain the code when you upgrade your extension. Below is the simple process to create the upgrade codeunit:
    1. Create a new codeunit say 50001 with the name “My Extension Upgrade CodeUnit”.
    2. Declare two functions in the Globals of your codeunit with the name:
      1. OnNavAppUpgradePerDatabase()
      2. OnNavAppUpgradePerCompany()
    3. Make sure these functions are global.
  4. You are ready to publish your first extensions. To publish the extension first of all you have to export the modified objects in .txt files. However, it is recommended to compare the whole database but for now it is ok, to compare only the modified objects.
  5. After step 4, you should have two text files
    1. StandardObjects.txt containing all the standard object of NAV.
    2. ModifiedObjects.txt containing all the customized/modified objects.
  6. Now open PowerShell ISE as administrator.
  7. The basic idea, is to split the exported txt files into individual files. To do this you can use powershell command:
    1. Split-NAVApplicationObjectFile -Source “SourceFilePath.txt” -Destination “DesitnationPath” -Force 
  8. After splitting compare these files one by one, which leads to the generation of Delta Files. These Delta files are nothing, but the changes in the two files. To do this:
    1. Compare-NAVApplicationObject -OriginalPath “OriginalPath” -ModifiedPath “Modified Path” -DeltaPath “Delta Files Path” -Force
  9. Once the Delta files have been generated, its time to generate the manifest file. Manifest file contains the information of the app like app name, publisher name, version etc. To do this:
    1. New-NAVAppManifest -Name “SYNERGY-IT” -Publisher “Zohaib Ahmed” -Version “1.0.0.0” | New-NAVAppManifestFile -Path “C:\Users\zohaib.ahmed\Desktop\Extensions file\Manifest.xml” -Force
  10. After the manifest file has been generated, it’s time to publish your first extension (.NAVX) package. To do this:
    1. Get-NAVAppManifest -Path “ManifestFilePath.xml” | New-NAVAppPackage -Path “NAVX Package Path” -SourcePath “Delta Files Path”
    2. Publish-NAVApp -ServerInstance DynamicsNAV100 -Path “C:\Users\zohaib.ahmed\Desktop\Extensions file\MyFirstExtension.navx” -SkipVerification
  11. Its time to install your extensions. To do this:
    1. Install-NAVApp -ServerInstance DynamicsNAV100 -Name “SYNERGY-IT” -Version 1.0.0.0

Once installed successfully, you are able to see the new fields on the customer card page in the Windows client (as shown in the screenshot):

5

Congratulations! you have created your first extension in Dynamics NAV.

To Download the powershell script (used to create an extension) : Click Here

To Download the Complete demo files (including folder): Click Here

Appendix (Demo Folder Directory Structure)

6

  • “Combined files” folder contain the exported Standard and Customized Developed objects.
  • “Delta folder” contain the differences in the standard and customized objects.
  • “Development original files” contains the splitted customized objects  (one object per file).
  • “Standard original files” contain the splitted standard objects (one object per file).

I hope you got the basic concepts of how to develop an extension. If you have any question/confusion/query feel free to comment on post. If you like my article then don’t forget to share it.

Advertisements

Author: zohaib.ahmed

I am an IT professional, a GEEK by nature who loves to get his hands dirty by experiencing new technologies in the domain of computer science. I am doing development in different domain since last 3 years. Right now, I am working as a Dynamics NAV technical consultant.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s