Skip to main content

Export and compare

The script performs a export and compare of Microsoft Dynamics NAV objects. The script does the following:

  1. Exports two sets of application objects from two different databases (original and modified) using the Export-NAVApplicationObject cmdlet.
  2. Splits the exported application object files into separate files for each object type using the Split-NAVApplicationObjectFile cmdlet.
  3. Compares the original and modified application objects and generates a delta file that contains the differences between the two using the Compare-NAVApplicationObject cmdlet.

The script requires the Microsoft Dynamics NAV Model Tools module to be imported and uses a number of parameters to configure the script, such as the database server and name for the original and modified databases, the path for the application object files, and the filter for the application objects to export.

#-------------------------------PRE STEP------------------------------- 
$skipOriginalExport = $false;
$SkipModifiedExport = $false;

$DatabaseServerOriginal = "";
$DatabaseServerModified = ".";
$DatabaseNameOriginal = "";
$DatabaseNameModified = "";

$ModifiedIdentifier = "";
$OriginalIdentifier = "";

$ApplicationObjectFile = "C:\Temp\MERGE(PS)\";

$ExportObjectFilter = "";

$RTCFolderPath = "";
#-------------------------------DO NOT EDIT UNDER THIS LINE-------------------------------

$PathForMicrosoftDynamicsNavModelTools = (Join-Path $RTCFolderPath "Microsoft.Dynamics.Nav.Model.Tools.psd1");

Import-Module $PathForMicrosoftDynamicsNavModelTools -DisableNameChecking;

Function CreateFolderStructure {
[cmdletbinding()]
Param (
[string]$ApplicationFile,
[string]$Identifier
)
Process {
$Path = Join-Path $ApplicationFile $Identifier
if (!(Test-Path $Path)) {
$null = New-Item -ItemType directory -Path $Path
}
$Path += "\"
Write-Output $Path
}
}

$Delta = "DELTA";
$Modified = "MODIFIED" + $ModifiedIdentifier;
$Original = "ORIGINAL" + $OriginalIdentifier;

$DeltaPath = CreateFolderStructure -ApplicationFile $ApplicationObjectFile -Identifier $Delta;
$ModifiedPath = CreateFolderStructure -ApplicationFile $ApplicationObjectFile -Identifier $Modified;
$OriginalPath = CreateFolderStructure -ApplicationFile $ApplicationObjectFile -Identifier $Original;

$OriginalFile = $ApplicationObjectFile + $Original + ".txt";
$ModifiedFile = $ApplicationObjectFile + $Modified + ".txt";

#-------------------------------STEP 1-------------------------------

$ScriptBlockExportNAVApplicationObject = {
Import-Module $args[0] -DisableNameChecking;
if (!$args[2]) {
Export-NAVApplicationObject -DatabaseServer $args[3] -DatabaseName $args[4] -Path $args[5] -Filter $args[1] -ExportTxtSkipUnlicensed -Force
}
}

$ExportJob1 = start-job -ScriptBlock $ScriptBlockExportNAVApplicationObject -ArgumentList $PathForMicrosoftDynamicsNavModelTools,$ExportObjectFilter,$skipOriginalExport,$DatabaseServerOriginal,$DatabaseNameOriginal,$OriginalFile
$ExportJob2 = start-job -ScriptBlock $ScriptBlockExportNAVApplicationObject -ArgumentList $PathForMicrosoftDynamicsNavModelTools,$ExportObjectFilter,$SkipModifiedExport,$DatabaseServerModified,$DatabaseNameModified,$ModifiedFile

Wait-Job $ExportJob1,$ExportJob2;

#-------------------------------STEP 2-------------------------------

$ScriptBlockSplitNAVApplicationObjectFile = {
Import-Module $args[0] -DisableNameChecking;
if (Test-Path ($args[1])) {
Split-NAVApplicationObjectFile -Source $args[1] -Destination $args[2] -PreserveFormatting;
}
}

$SplitJob1 = start-job -ScriptBlock $ScriptBlockSplitNAVApplicationObjectFile -ArgumentList $PathForMicrosoftDynamicsNavModelTools,$OriginalFile,$OriginalPath;
$SplitJob2 = start-job -ScriptBlock $ScriptBlockSplitNAVApplicationObjectFile -ArgumentList $PathForMicrosoftDynamicsNavModelTools,$ModifiedFile,$ModifiedPath;

Wait-Job $SplitJob1,$SplitJob2;

#-------------------------------STEP 3-------------------------------

Compare-NAVApplicationObject -DeltaPath $DeltaPath -ModifiedPath $ModifiedPath -OriginalPath $OriginalPath;