Saturday, September 24, 2016

Implement Extensions in NAV

Below is the easiest way I found to implement extensions in NAV.

Let's Start!

The above diagram shows how extensions work and the idea behind bringing extensions into existence. Extensions can be installed independently on different tenants belonging to the same service and each tenant will have only the functionality of the extensions installed on it.

Extensions can co-exist in a tenant and independently as well. In the above diagram Extension 1 and 2 are installed on Tenant 1 and Tenant 2. While Extension 3 is only installed on Tenant 3 and likewise.

7 Easy steps to implement extensions in NAV are as follows:

NOTE: Before we continue, please note that,
  • Original or Unmodified are one and the same thing.
  • I will work with NAV 2016 first version. The cumulative updates have some issues when we install an extension on them. The build number is shown below highlighted in yellow.



Step 1 - Export modified objects and original objects separately to MODIFIED & ORIGINAL folders separately.

For this post I am going to use Location Table, Location Card and a New Codeunit (named 'Subscriber Events Mgmt').

Step 1.1 - To avoid confusion, create folders as shown below, somewhere in your PC.



Step 1.2 - Determine the objects you are going to modify and export these objects in text format separately to 'Original_Objects' Folder. I will export Location Table and Location Card.


Also, export these unmodified objects in FOB format somewhere in your PC. After we modify these objects and export the modified objects in text format, we need to import the unmodified objects back into NAV. After all, that is what extensions is all about - No modifications in C/AL and we still get our way with customizing NAV.


Step 1.3 - Modify the objects. I have added 2 new fields in Location Table and Location Card as shown below,
Location Table

Location Card

Step 1.4 - Now I will create a new Codeunit and add a new function in it named 'OnLocationAfterInsert', the properties of this function are shown below,


Now, the code which I have added in this function is shown below,


In case you do not know, The parameters are added by the system itself once we select a value in the EventFunction property of a subscriber function.

Step 1.5 - Export these modified objects separately in 'Modified_Objects' Folder.


Step 1.6 - Import the unmodified objects FOB which was exported by you in step 1.2 back into NAV and delete any new objects you have made in the process. In this scenario Codeunit 50000 is the new object.

Step 2 – Run PowerShell ISE as Administrator and Import NavModelTools into it. If you do not have an idea check How to import nav model tools to powershell.

Step 3 - Create Delta file.

Step 3.1 - Copy 'Compare-NAVApplicationObject' and paste this in Name text-box under Commands tab in PowerShell ISE. A window like below will show up.


Step 3.2 - Double-click on the text highlighted in yellow in the picture above. Parameters tab will show up just below the highlighted area as shown below. Enter the following information in Parameters:
  • DeltaPath (Newly created Delta files will be stored in this path), 
  • ModifiedPath (the path where modified objects in text format exist),
  • Original Path (the path where unmodified objects in text format exist).
I have already entered this info and a screenshot is shown below,


Step 3.3 - Hit Run highlighted in orange. And and output like below will appear.


Also, check the Delta files created in the path mentioned by you in the DeltaPath in Step 3.2.



Step 4 - Create Manifest file.

Step 4.1 - Copy 'New-NAVAppManifest' and paste this in Name text-box under Commands tab in PowerShell ISE. A window like below will show up.



Step 4.2 - Double-click on the text highlighted in orange in the picture above. (Forget the light green highlight for now, we will use it in step 4.5.) Parameters tab will show up just below the highlighted area as shown below. Enter the following information in Parameters:
  • Name (Name of your extension)
  • Publisher (Your co.'s name or whatever you like)
  • You may enter Description and Version as well, I will leave them blank for now.


Step 4.3 - Hit Insert highlighted in orange. Do not run at this moment, this applet needs to run in combination with another applet mentioned in Step 4.5.

Step 4.4 - Add | at the end of the command inserted in the dark blue area. The command will look like shown below,


Step 4.5 - Double-click on the text highlighted in light green in the picture shown in Step 4.1. Parameters tab will show up just below the highlighted area as shown below. Enter the following information in Parameters:
  • Path (Newly created Manifest File will be stored here.) This Path has 2 parts:
    • First is, Underlined in Red in the picture below, this is the path where you want to store your Manifest file.
    • Second is, Underlined in Light Blue, this is the name of your manifest file. Add .xml at the end like I have done shown below.



Step 4.6 - Hit Insert highlighted in orange. Now place your cursor at the end of the just inserted command and hit Enter.

Open the path which was entered by you to store the Manifest file and you will be able to see an XML file there like the one shown below,

NOTE: Manifest file is a file which carries the info like Name, Publisher etc. of the extension. We entered this info in Step 4.2.

Step 5 - Create .navx package.

Step 5.1 - Copy 'Get-NAVAppManifest' and paste this in Name text-box under Commands tab in PowerShell ISE. Double-click on the applet which shows up. In the Parameters tab enter the following information in Parameters:
  • Path - Enter the path of the Manifest file which was created in Step 4.6.

Step 5.2 - Hit insert and Add | at the end of the command inserted in the dark blue area.

Step 5.3 - Copy 'New-NAVAppPackage' and paste this in Name text-box under Commands tab in PowerShell ISE. Double-click on the applet which shows up. In the Parameters tab enter the following information in Parameters:

  • Path (Newly created navx Package will be stored here.) This Path has 2 parts:
    • First is, Underlined in Red in the picture below, this is the path where you want to store your Package.
    • Second is, Underlined in Light Blue, this is the name of your Package. Add .navx at the end like I have done shown below.
  • SourcePath - The path in which the delta files exist which were created in Step 3.3.


Step 5.4 - Hit Insert. Now place your cursor at the end of the just inserted command and hit Enter.


Open the path which was entered by you to store the Package and you will be able to see a NAVX File there like the one shown below,


Step 6 - Publish NAV app. This step takes a little time to process.

Step 6.1 - Copy 'Publish-NAVApp' and paste this in Name text-box under Commands tab in PowerShell ISE. Double-click on the applet which shows up. In the Parameters tab enter the following information in Parameters:
  • Path - Enter the path of the NAVX Package file which was created in Step 5.4.
  • ServerInstance - The Name of the Server Instance on which you want to publish the NAV app.


Step 6.2 - Hit Run and then Get the info about the published app to know if the publish was successful.  Copy 'Get-NAVAppInfo' and paste this in Name text-box under Commands tab in PowerShell ISE. Double-click on the applet which shows up. In the Parameters tab enter the following information in Parameters:
  • ServerInstance - The Name of the Server Instance on which you published the NAV app in Step 6.1.
Output will show up in the dark blue area like shown below,


Step 7 - Install the app.

Step 7.1 - Copy 'Install-NAVApp' and paste this in Name text-box under Commands tab in PowerShell ISE. Double-click on the applet which shows up. In the Parameters tab enter the following information in Parameters:
  • Name - Enter the name of the extension which was given by you in Step 4.2.
  • ServerInstance - The Name of the Server Instance on which you want to install the extension.

Step 7.2 - Hit Run and your NAV app is installed on this server instance.

Step 7.3 - Last Step of all - Test the extension by running RTC.
  • Open Locations and I have opened table fields for BLUE and we can see the new fields "Created By" and "Created Date".


  • Now, insert a new Location. Lets enter TEST in Code and hit enter. The result looks like below,


And we're done with implementing the Extension in NAV. The process is bit long but the results are really cool. I do not have any code in C/AL, no modified objects and still I am working in a customized system.

Keep Learning!!
Ishwar :)
#KnowledgeForNAVTechies