We can use our Delta file to build our application, based on a new version of the software that also uses PowerShell commands.
PowerShell is, as the name implies, a very powerful tool that not only supports Dynamics NAV, but most Microsoft applications including the SQL Server. This allows us to generate a single script that restores a new SQL Database, applies our Delta file, compiles objects, and runs the test.
Let's go through this process step by step using an example script. In this script, the parameters are hardcoded for readability. It is recommended that you use variables instead.
$NavIde = "C:Program Files (x86)Microsoft Dynamics NAV80RoleTailored Clientfinsql.exe" Set-ExecutionPolicy unrestricted import-module "C:Program Files (x86)Microsoft Dynamics NAV80RoleTailored ClientNavModelTools.ps1" import-module "C:Program FilesMicrosoft Dynamics NAV80ServiceNavAdminTool.ps1" Push-Location import-module sqlps
Set-NAVServerInstance "bedandbreakfast" –Stop invoke-sqlcmd -ServerInstance ".NAVDEMO" -Query "ALTER DATABASE [BedAndBreakfast (8-0)] SET SINGLE_USER WITH ROLLBACK IMMEDIATE" invoke-sqlcmd -ServerInstance ".NAVDEMO" -Query "DROP DATABASE [BedAndBreakfast (8-0)]" invoke-sqlcmd -ServerInstance ".NAVDEMO" -Query "RESTORE DATABASE [BedAndBreakfast (8-0)] FROM DISK = N'E:Demo Database NAV (8-0).bak' WITH FILE = 1, MOVE N'Demo Database NAV (8-0)_Data' TO N'C:SQLFilesDemo Database NAV (8-0)_Data.mdf', MOVE N'Demo Database NAV (8-0)_Log' TO N'C:SQLFilesDemo Database NAV (8-0)_Log.ldf', NOUNLOAD, STATS = 5" Invoke-Sqlcmd -ServerInstance ".NAVDEMO" -Database "BedAndBreakfast (8-0)" -Query "CREATE USER [NT AUTHORITYNETWORK SERVICE] FOR LOGIN [NT AUTHORITYNETWORK SERVICE]" Invoke-Sqlcmd -ServerInstance ".NAVDEMO" -Database "BedAndBreakfast (8-0)" -Query "exec sp_addrolemember 'db_owner', 'NT AUTHORITYNETWORK SERVICE'" Set-NAVServerInstance "bedandbreakfast" –Start
Export-NAVApplicationObject -DatabaseName "BedAndBreakfast (8-0)" -Path "E:BandBTarget.txt" -DatabaseServer ".NAVDEMO" Split-NAVApplicationObjectFile -Source "E:BandBTarget.txt" -Destination "E:BandBTarget" -Force
$MergeResult = Update-NAVApplicationObject -TargetPath "E:BandBTarget" -DeltaPath "E:BandBDelta" ` -ResultPath "E:BandBResult" -Force $MergeResult | Where-Object UpdateResult -eq Unchanged | foreach { Remove-Item -Path $_.PSPath } -Verbose Join-NAVApplicationObjectFile -Source "E:BandBResult" -Destination "E:BandBResult.txt"
Import-NAVApplicationObject -DatabaseName "BedAndBreakfast (8-0)" -Path "E:BandBResult.txt" -DatabaseServer ".NAVDEMO" Compile-NAVApplicationObject -DatabaseName "BedAndBreakfast (8-0)" -DatabaseServer ".NAVDEMO" -Filter 'Compiled=No'
Invoke-NAVCodeunit -ServerInstance "bedandbreakfast" -CodeunitId 84099 -CompanyName "CRONUS International Ltd."