Thank you for landing here.
It’s quite common nowadays to hear NAV people talking about Dynamics 365, AppStore, extensions, new AL language and the Visual Studio Code.
So extension is a concept that sooner or later NAV developers need to grasp.
In this blog I will create one simple extension. I have seen a few demos on the web, but I had a few issues following them. I will highlight these issues as I go.
I encourage everyone to visit msdn page on this topic.
1. Setting up your working space
On my development machine I installed NAV 2017 CU 9. I will be working with 3 databases which initially will be restored from your NAV DVD, from the folder below:
SQLDemoDatabase\CommonAppData\Microsoft\Microsoft Dynamics NAV\100\Database
- restore via SQL Server Management Studio the Demo database as Demo Database NAV (10-0) (we won’t touch this – it will be our ORIGINAL DB)
- restore via SQL Server Management Studio the Demo database as TestExtension (we will make modifications on this database – it will be our MODIFIED DB)
- restore via SQL Server Management Studio the Demo database as ApplyExtension (we will install our extension here – it will be our TARGET DB)
- create a NAV service(I named mine TestExtension) pointing to the database you will be working with in the development environment, in our case is TestExtension
- created 3 folders on your local drive: ORIGINAL, MODIFIED, DELTA
2. Create extension content
I added field 50000 “Planet No.” – Integer on table 14 Location.
I added this new field to Page 15, “Location List”.
I created a new codeunit, 50000, TestExtension, with 2 empty and local functions:
And these are the 3 objects:
3. Populate local folders: ORIGINAL,MODIFIED and DELTA:
a. Populate ORIGINAL:
Point Service tier towards Demo Database NAV (10-0) and from Dev. environment export all objects (or just Table 14 and Page 15 if you want a faster text file processing) as Original.txt. As this file contains a concatenation of all objects we will need to split the big file into smaller ones (one per object). In the ORIGINAL folder create a Split folder. From the Dynamics NAV 2017 Administration Shell run:
Split-NAVApplicationObjectFile -Source .\original\*.txt -Destination .\original\split\
And this is the end-result:
b. Populate MODIFIED
Point Service tier towards TestExtension and from Dev. environment export all objects (or just Table 14 and Page 15 if you want a faster text file processing) as Modified.txt.
For the same reason as in the previous step split big Modified file:
Split-NAVApplicationObjectFile -Source .\Modified\*.txt -Destination .\Modified\split\
c. Populate DELTA
To create Delta files run:
Compare-NAVApplicationObject -OriginalPath .\ORIGINAL\SPLIT\ -ModifiedPath .\MODIFIED\Split\ -DeltaPath .\DELTA\
Processed 4965 objects:
Inserted 1 objects
Deleted 0 objects
Changed 2 objects
Identical 4963 objects
Failed 0 objects
Have a look at the composition of a Delta file:
4. Create NAVX file (extension file)
From the Microsoft Dynamics NAV 2017 Administration Shell run:
New-NAVAppManifest -Name "FirstExtension" -Publisher "SVIRLAN.com" -Version "22.214.171.124" | New-NAVAppPackage -Path FirstExtension.navx -SourcePath .\DELTA
5. Publish extension
To publish the new extension in the ApplyExtension database, point your service tier towards the ApplyExtension database and from the Microsoft Dynamics NAV 2017 Administration Shell run:
Publish-NAVApp -Path .\FirstExtension.navx -ServerInstance TestExtension -SkipVerification
Open page 2500 “Extension Management” and click Install on our new extension:
You can Un-install the extension(via action on Page 2500) and you can Un-publish it via “Un-Publish” powershell command.
Let’s have a look at what we’ve got by applying our extension to the ApplyExtension database:
The Locations page contains the new field:
But when looking at the objects we dont see the codeunit 50000, the new fields nor the changes in the Version List:
Moreover, trying to add the field 50000 in the Location table prompts this system error:
This makes sense!
The code in table14 and Page 15 remained as delivered by Microsoft, and the extension fields are somehow managed internally via system objects like tables 2000000150 – 2000000163.
1. First error I encountered was: “The package contains changes to the database schema that are not handled in upgrade code.”
I needed a codeunit to subscribe to standard published events:
That’s the reason I have codeunit 50000 and the 2 functions:
PS C:\docs\blogs\Extensions> New-NAVAppManifest -Name "Proseware SmartStuff" -Publisher "Proseware, Inc." -Version "126.96.36.199" | New-NAVAppPackage
-Path MyExtension.navx -SourcePath DELTA
New-NAVAppPackage : The package contains changes to the database schema that are not handled in upgrade code.
At line:1 char:100
+ ... 188.8.131.52" | New-NAVAppPackage -Path MyExtension.navx -SourcePath DELT ...
+ CategoryInfo : InvalidArgument: (Microsoft.Dynam...ewNavAppPackage:NewNavAppPackage) [New-NAVAppPackage], InvalidOperationExcepti
+ FullyQualifiedErrorId : Microsoft.Dynamics.Nav.Apps.Tools.NewNavAppPackage
2. Second issue happened when running the Publish-NAVApp command: “Access is denied. You need to be a member of the local Administrators group on the server to run this cmdlet.”
Need to run powershell as Admin:
PS C:\docs\blogs\Extensions> Publish-NAVApp -Path .\FirstExtension.navx -ServerInstance TestExtension -SkipVerification
Publish-NAVApp : Access is denied. You need to be a member of the local Administrators group on the server to run this cmdlet.
At line:1 char:1
+ Publish-NAVApp -Path .\FirstExtension.navx -ServerInstance TestExtens ...
+ CategoryInfo : NotSpecified: (:) [Publish-NAVApp], NavCommandException
+ FullyQualifiedErrorId : MicrosoftDynamicsNavServer$TestExtension,Microsoft.Dynamics.Nav.Apps.Management.Cmdlets.PublishNavApp
3. In case any of the powershell cmdlets is not recognized in your environment run:
PS C:\docs\blogs\Extensions> Import-Module “C:\Program Files (x86)\Microsoft Dynamics NAV\100\RoleTailored Client\Micro
Thank you for reading, sharing, commenting, liking, following 🙂