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

Upgrade Dynamics NAV through PowerShell – 1

August 11th, 2017 Intech SystemJignesh Dhandha 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.

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.

About Intech

Intech Systems is a three-cloud Microsoft-certified partner that boasts deep expertise in providing digital transformation solutions for organizations by leveraging the Microsoft 365, Dynamics 365, and Azure solution stack. Intech is recognized as a top-tier Microsoft implementation partner globally and specializes in transformative technology solutions such as ERP (Enterprise Resource Planning), CRM (Customer Relationship Management), Business Process Automation, Business Intelligence, Cloud Infrastructure, Data Management, Productivity & Collaboration and Generative AI (Gen-AI) solutions. As a trusted Microsoft Solutions Partner, we are capable of doing complex technology implementations catered to an organization’s specific needs & also rapid solution implementation such as our Microsoft Dynamics 365 Business Central implementation packages. We pair our implementations with end-to-end customer support, offshore development & 3rd party integrations. With offices in India, USA (United States of America), and Singapore, we work with clients across globe to empower businesses with cutting-edge technology solutions. Our latest services aim at delivering business ready AI solutions to the customer, like our  Microsoft Copilot Consulting Services & Solutions for small, medium & large enterprises. Intech’s expertise lies in building software solutions for Manufacturing, Professional Services & Healthcare.  Our Dealer Management SystemSales and Service CRM for Manufacturing, Field Force Automation for Pharmaceuticals and Manufacturing Central are some of our leading industry solutions. Intech’s vision is to catalyze digital futures for operation-centric industries globally, we are at the forefront of innovation, helping organizations drive growth and innovation like never before. Contact Us to learn more.
Contact Us

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

What's New

Microsoft Dynamics 365 Voice Channel: Transforming Customer Service for the Digital Age
Dynamics 365 October 17th, 2024

Microsoft Dynamics 365 Voice Channel: Transforming Customer Service for the Digital Age

A Day in the Life of Customer Service: Sound Familiar? Picture this: It's 9:05 AM...

Business Central's Project Management Enhancements
Business Central May 4th, 2024

Business Central Project Management Enhancements: Power Up Your Projects

As businesses grow and projects multiply, managing invoices efficiently becomes crucial. In the 2024 release wave...

AI March 18th, 2024

Exploring Trends for AI in CRM and ERP Systems [2024]

Exploring Trends for AI in CRM and ERP Systems [2024] Did you know that a...