Auto Import of Objects from Dev to Test system


I got a requirement to develop a solution so that technical changes can be moved automatically from Dev to Test system.

Why we want to do this - 

1) If developers have direct access on test system then there is a high risk that they will be developing directly on test system and this results in poor documentation, plus more issues when things move to prod.

2) Well there are custom solutions available, but the additional features that are being delivered are not needed.

How i did this - 

1) Created a powershell script.

2) Created a bat file.

3)  Created a directory to store the imported files.

4) Created a task in application server to run the bat file.

Detailed Steps - 

1) Powershell script - 


2) create a notepad file and save it as .bat file with following code - 

3) Look for task scheduler -


4) Create a task - 

5) Specify path of your bat file, define the intervals when you want to run the task.




Powershell Script - 

Save this as AutoImport.Ps1

******************************************************************

Set-ExecutionPolicy Unrestricted -InformationAction SilentlyContinue -Force Process  –Confirm:$false

Import-Module "${env:ProgramFiles(x86)}\Microsoft Dynamics NAV\100\RoleTailored Client\Microsoft.Dynamics.Nav.Model.Tools.psd1" -WarningAction SilentlyContinue | out-null -InformationAction SilentlyContinue

Import-Module "$env:ProgramFiles\Microsoft Dynamics NAV\100\Service\NavAdminTool.ps1" -WarningAction SilentlyContinue | Out-Null -InformationAction SilentlyContinue  

Import-Module "${env:ProgramFiles(x86)}\Microsoft Dynamics NAV\100\RoleTailored Client\Microsoft.Dynamics.Nav.Apps.Tools.psd1" -WarningAction SilentlyContinue | Out-Null -InformationAction SilentlyContinue  

$ObjectPath = 'Specify the path where developers will export there objects example \\Server\Directory\ExportFolder\*.fob'
$ObjectPathtxtfile = 'Specify the path where developers will export there objects example \\Server\Directory\ExportFolder\*.txt path is defined 2 times for fob & txt files'
$DbName = 'Type in your database name'
$DbServer = 'Type in your database server, you can find it in nav by going to file -> Database --> Information'
$ServerInstance = 'Type in your server instance'
$AppServerName = 'Type in your application server name'
$MgmtPort = 'Type in management service port'
$Archivepath = "Type in the path where you want to store the objects after they have been imported"

Import-NAVApplicationObject -Path $ObjectPath -DatabaseName $DbName -DatabaseServer $DbServer -NavServerInstance $ServerInstance -ImportAction Overwrite -NavServerName $AppServerName -NavServerManagementPort $MgmtPort -SynchronizeSchemaChanges Force -InformationAction SilentlyContinue -ErrorAction SilentlyContinue -WarningAction SilentlyContinue  –Confirm:$false

Move-Item -Path $ObjectPath -Destination $Archivepath  -Force  –Confirm:$false

Move-Item -Path $ObjectPathtxtfile -Destination $Archivepath -Force   –Confirm:$false

*****************************************************************

Save this file as AutoImport.bat -

*******************************************
@ECHO OFF
Powershell.exe -Command "& 'C:\Prateek\Auto Import\AutoImport.ps1'"
EXIT
*******************************************

THIS CODE IS ONLY FOR LEARNING PURPOSES & COMES WITHOUT ANY GURANTEE/WARRANTY.

Comments

Post a Comment

Popular posts from this blog

STX File Issue - Errors in the text conversion Dynamics NAV 2017

Powershell in Navision