Register For Our Live Webinar WorkshopRegister Now

Technology trends, insights, success
stories and other helpful resources.

Upgrade Dynamics NAV through PowerShell – 1

August 11th, 2017 Intech SystemIntech System Dynamics NAV, Microsoft Dynamics

This blog is the first part of how you can automatically upgrade Dynamics NAV through PowerShell.
With release of every new version of Microsoft Dynamics NAV, Microsoft offers enhancements and new features. For upgrading to Dynamics NAV 2016, you need to upgrade your code and database both to the new version. Usually manual upgrade process is tedious and takes much of your time. Microsoft introduces new concept, – “Automatic Upgrade through PowerShell”. Doing Upgrade process by Windows PowerShell will make your work very easier and also save lot of time.
There are mainly two steps in upgrade process:

  1. Code Upgrade
  2. Data Upgrade

During an upgrade to Dynamics NAV 2016, you must first upgrade the application code, and then you upgrade the data. By using Windows PowerShell, you can automate upgrade application code process and complete data upgrade process in a single click. You can also use the same scripts to test each step in your upgrade process before you upgrade production databases.
If you are maintaining multiple Dynamics NAV databases, for example you are supporting multiple customers with the same Dynamics NAV application, you can reduce the time of upgradation of each database by using Windows PowerShell scripts. In this case, you can upgrade the application locally, and then use scripts to roll out the upgrade of each database with reduced unavailability for each database. You can combine this automated upgrade with a migration to multi-tenancy if this makes maintenance easier for you.

To start the upgrade process, create four folders on your computer and name them as follows:

  • ORIGINAL : For the application objects from the baseline version, such as the original release of Microsoft Dynamics NAV 2013.
  • MODIFIED : For the application objects from the modified version, such as the customer’s database.
  • TARGET : For the application objects from Microsoft Dynamics NAV 2016.
  • RESULT : For the application objects that are the result of the application merge. It will also contain zero or more .CONFLICT files that describe conflicting code.

 

The following list describes the main steps of upgrading the application code:

 

1.  Import the module command
  • Open the Windows PowerShell ISE as administrator.
  • Before executing any command, import NAVModelTools Module through this command:
    Import-Module ‘C:\Program Files (x86)\Microsoft Dynamics NAV\100\RoleTailored Client
    R6\NavModelTools.ps1’
2.  Prepare the application object text files.
  • First, export all application objects from the original version. Do not export system tables. Name the file txt, and save it in the ORIGINAL folder.
  • For example, the Microsoft.Dynamics.Nav.Model.Tools.psd1 module includes a function, Export-NAVApplicationObject, that runs the ExportObjects command. This means that you can run a command such as the following:
    • Export-NAVApplicationObject –DatabaseServer MyServer –DatabaseName “Demo Database NAV (7-0)” –Path C:\Upgrade\ORIGINAL\OldBaseVersion.txt
    • Next, export all relevant application objects from the modified version. Do not export system tables. Name the file txt, and save it in the MODIFIED folder.
    • Finally, export all application objects from the new base version. Do not export system tables. Name the file txt, and save it in the TARGET folder.
3.  Merge versions

To create the application for the new database, you must merge these three sets of application objects. You can use the Merge-NAVApplicationObject cmdlet to merge the three sets of application objects.
There are three process performed by the system when automatic merging process executed through PowerShell: Reading Objects, Comparing Objects and Writing Objects.
Merging time might vary depending on the number of objects that you are merging and the number of differences found. The RESULT folder will contain a text file for each application object. The result of the merge is shown when the cmdlet completes, including a description of any application objects with conflicting code. These conflicts are stored in .CONFLICT files in the RESULT folder. You can import all objects in the RESULT folder into the new Microsoft Dynamics NAV 2016 database, or you can analyse the conflicts before you import the objects.
As per the image below, the automatic merging process through PowerShell is executed and after completing this process, system will generate the Summary related to Automatic Merging Process.
System also display how many percentage merging has been done.

 

Drytac US Summary

 

4.  Resolve conflicts

Depending on the application that you are upgrading, you can choose to analyze the conflicting code before you import the merged objects into the development environment. The conflicts are shown in the merged text files but are also identified in .CONFLICT files in the RESULT folder. Subfolders then contain copies of the source files from the versions that have conflicting code. You can analyze the conflicts in any tool, make the relevant changes, and then run the merge operation again.
Alternatively, you can import the merged files into the development environment, and resolve the conflicts there.

5.  Import and compile the merged application objects.

After completing the merge, import the new custom version into the new Microsoft Dynamics NAV 2016 database, and then compile all objects. Resolve compilation errors, if any, before you can continue. The text files with the merged application objects include successfully merged code, and code that is partially merged. You can import the partially merged objects into the Microsoft Dynamics NAV 2016 development environment and resolve the conflicts there. At this stage, you have a new database with a fully upgraded application.
For example, the Microsoft.Dynamics.Nav.Model.Tools.psd1 module includes a function, Import-NAVApplicationObject, that runs the ImportObjects command. This means that you can run a command such as the following:

  • Join-NAVApplicationObject –Source C:\Upgrade\RESULT\*.txt -Destination C:\Upgrade\all-merged.txt
  • Import-NAVApplicationObject –DatabaseServer MyServer –DatabaseName “My Upgraded App” –Path C:\Upgrade\all-merged.txt

In this example, you first join the many text files into a single file, which you then import into an existing, empty database. When you compile the objects, an error is thrown for each code conflict, and you can use the tools that are available in the development environment to resolve the conflicts.

6.  Export all objects

Now, export all objects to an objects.fob file to import them when performing the data upgrade. The export must include customized objects, upgraded reports, and all other Microsoft Dynamics NAV 2016 objects.
This completes the upgrade of the application code. Read our upcoming blog to learn how to upgrade the data in the database.
For more details, contact our Dynamics NAV consultants.

Recent Post

Corporate Profile

Request Demo Download Brochure
Contact Us

How we can help you!

Talk to Dynamics 365 experts for your concerns

Contact Us
Contact Us

How can we help? - Talk to Dynamics 365 experts for your concerns

    Join our mailing list for news updates, invitations, and more