Similar to the NAV 2018 Administration Shell, the NAV 2018 Development Shell provides access to PowerShell cmdlets for the management of application objects. Development tasks, such as object export, import, and compilation, can be automated with the Development Shell. The same as Administration Shell, NAV Development Shell can be run from the Start menu. On startup, it imports several modules. We will now take a closer look at one of them: Microsoft.Dynamics.Nav.Model.Tools.
To list all cmdlets available in the Microsoft.Dynamics.Nav.Model.Tools module, run this:
Get-Command -Module Microsoft.Dynamics.Nav.Model.Tools
As an alternative to the method described previously, the import/export procedure can be performed in the NAV Development Shell. To do it, run the following commands one by one.
The first cmdlet will export objects defined by the Filter parameter from the specified NAV server to the disk:
Export-NAVApplicationObject -DatabaseName "Demo Database NAV (11-0)"
-DatabaseServer "localhost\NAVDEMO" -Path "C:\NAV Objects\COD50500.txt"
-Filter "Type=Codeunit;ID=50500"
Typically, you apply a Filter based on the object type and name, but other object properties can be used for filtering as well. For example, you may want to export all modified objects:
Export-NAVApplicationObject -DatabaseName "Demo Database NAV (11-0)"
-DatabaseServer "localhost\NAVDEMO"
-Path "C:\NAV Objects\Modified.txt" -Filter "Modified=Yes"
Or export all object labeled with the version PACKT:
Export-NAVApplicationObject -DatabaseName "Demo Database NAV (11-0)"
-DatabaseServer "localhost\NAVDEMO"
-Path "C:\NAV Objects\COD50500.txt" -Filter "Version List=*PACKT*"
To import the objects, run the Import-NAVApplicationObject cmdlet:
Import-NAVApplicationObject -Path "C:\NAV Objects\COD50500.txt"
-DatabaseName "Demo Database NAV (11-0)" -DatabaseServer "localhost\NAVDEMO"
Imported objects must be compiled in the new database:
Compile-NAVApplicationObject -DatabaseName "Demo Database NAV (11-0)"
-DatabaseServer "localhost\NAVDEMO" -NavServerName DynamicsNAV110
-Filter "Type=Codeunit;ID=50500"
You can compile all objects in the database, or use the Filter parameter to select a subset.
Now, let's combine all these code samples into one Powershell function that can export, import, and compile the object with a single command. To do this, we will need the PowerShell IDE, which can be started from the Windows Applications menu. The application name is powershell_ide. Place the following code in the PowerShell editor and run it:
if ([Environment]::Is64BitProcess)
{
$RtcFolder =
'HKLM:\SOFTWARE\Wow6432Node\Microsoft\Microsoft Dynamics NAV\110\RoleTailored Client'
}
else
{
$RtcFolder = 'HKLM:\SOFTWARE\Microsoft\Microsoft Dynamics NAV\110\RoleTailored Client'
}
Test-Path $RtcFolder
$IdeModulePath = (Join-Path (Get-ItemProperty $RtcFolder).Path Microsoft.Dynamics.Nav.Ide.psm1)
Import-Module $IdeModulePath
function Deploy-ObjectsToTestServer
{
Param(
[Parameter(Mandatory = $true)]
[string] $DevelopmentDatabaseName,
[Parameter(Mandatory = $true)]
[string] $TestDatabaseName,
[Parameter(Mandatory = $true)]
[string] $DevelopmentServerName,
[Parameter(Mandatory = $false, ParameterSetName =
"SeparateTestServer")]
[string] $TestServerName,
[Parameter(Mandatory = $false, ParameterSetName =
"SingelServerSetup")]
[switch] $SingleServer = $true,
[Parameter(Mandatory = $true)]
[string] $NavServerInstance,
[Parameter(Mandatory = $true)]
[string] $ObjectFilter
)
if ($SingleServer)
{
$TestServerName = $DevelopmentServerName
}
[string] $tempFileName = [System.IO.Path]::GetTempFileName() +
".txt"
Export-NAVApplicationObject
-DatabaseName $DevelopmentDatabaseName -DatabaseServer
$DevelopmentServerName
-Path $tempFileName -Filter $ObjectFilter
Import-NAVApplicationObject
-Path $tempFileName -DatabaseName $TestDatabaseName -
DatabaseServer $TestServerName
Compile-NAVApplicationObject
-DatabaseName $TestDatabaseName -DatabaseServer $TestServerName
-NavServerName $NavServerInstance -Filter $ObjectFilter
}
Now you can easily prepare your modification for testing with a single command:
Deploy-ObjectsToTestServer -DevelopmentDatabaseName "Demo Database NAV (11-0)" -TestDatabaseName "NAV 110 Test Database" -DevelopmentServerName localhost\NAVDEMO -SingleServer -NavServerInstance "NavTestServer" -ObjectFilter "ID=50500..50599"
This command will export all objects with IDs from 50500 to 50599 from the development database, Demo Database NAV (11-0), into a temporary file, import it into the NAV 110 Test Database, and compile all imported objects.