Friday 19 February 2016

Export and Split Navision objects using Windows PowerShell in NAV 2015

We are following some simple steps for export the Nav application objects:

1.  Open Windows PowerShell ISE and Load Nav Development Shell Command.
In Start Menu Just search Windows PowerShell ISE and open it.
Now you will see below screen.












Now to load Nav development shell command into Windows PowerShell ISE just run below command then you access all function and command which are available in Microsoft.Dynamics.Nav.Model.Tools.Module.

Command :- Import-Module “C:\Program Files (x86)\Microsoft Dynamics NAV\80\RoleTailored Client\Microsoft.Dynamics.Nav.Model.Tools.psd1" -force







Run its command by using Run Scipt(F5) {Tools - Run/Continue}.

Now we will see  how to Export and Split Nav Objects.

2 Export Nav Object using Windows PowerShell.

We used below cmdlet for export.
Command -  Export-NAVApplicationObject

Syntax  - Export-NAVApplicationObject FilePathwithName -DatabaseServer 'ServerName' -DatabaseName 'DatabaseName' -Filter filters -LogPath 'Log File Path'

FilePathWithName - The path and file name to which you export objects. This parameter is required.
 Exp  - D:\SP\Source\Tables.txt

ServerName :- The Name of  the database server on which you want to run the command.
Exp:- dell-pc (Localhost)

DatabaseName :- The database in which the objects that you want to export.

filters :- A filter on the Objects Table. following table shows the fields in the objects table on which you can filter,

Object table field
Values
Example
Type
Table, Codeunit, Page, Report, XMLport, Query
Type=Table|Page
ID
Integer or range of integers
ID=60000..60010
Name
Any valid object name
"Name=Purchase Header"
Modified
yes, no, 1, 0
Modified=yes
Compiled
yes, no, 1, 0
Compiled=0
Date
Date, in the numeric format determined by your regional settings
"Date=01/12/2012"
Time
Time, in the numeric format determined by your regional settings
"Time=12:00:00"
Version List
Any valid version
"Version List=NAVW17.00"
Caption
Any valid caption
"Caption=Company Information"
Locked
Yes, no, 1, 0
Locked=1
Locked By
Domain\username
"Locked By=dell-PC\sonu.panwar"

Log File Path :- The path  for the file that contain error  messages that result from the command, if  there are no  error come at run time then log file not created.
By Default, the file named naverrolog.txt  and is located in same location as finsql.exe.

Example:-  
Now run the below command for export objects form specified Database.

Export-NAVApplicationObject D:\SP\Source\test\Table.txt -DatabaseServer 'dell-pc' -DatabaseName 'ePuma-LocalDev' -Filter 'Type=Table;ID=1..10' -LogPath 'D:\SP\Source\test\' | Split-NAVApplicationObjectFile -Destination D:\SP\Dest\



After run it command show the below screen.








Now can check specified path "D:\SP\Source\test\"  in command then you found a txt file with specified name (Table.exe)








3- Split

Splits a  text file that contain two or more objects into separate text file for each objects

Syntax

Split-NAVApplicationObjectFle [-Source] <String> [[-Destiation] <String>] [-Force] [-PassThru][-PreserveFormatting]

Use that command  to split a text file that contains more then 2 Nav application Objects into  separate text file for Nav application objects. for example if you are export table 36  and table 37 to a single text file such as Table.txt., you can use the split command to create separate text file like as TAB36.txt and TAB37.txt.

---------
Now  we want to export the some filtered objects with the separate txt file, then we can use the both command with "|".
Export Comand |Split Command
Syntax
.- Export-NAVApplicationObject FilePathwithName -DatabaseServer 'ServerName' -DatabaseName 'DatabaseName' -Filter filters | Split-NAVApplicationObjectFle [[-Destiation] <String>]

It's command first export the objects in source location and after then splits and save in destination Location.

Example -  Now we want to export Tables 1 to 10 with separate txt file.

Command-
Export-NAVApplicationObject D:\SP\Source\test\Table.txt -DatabaseServer 'dell-pc' -DatabaseName 'ePuma-LocalDev' -Filter 'Type=Table;ID=1..10' -LogPath 'D:\SP\Source\test\' | Split-NAVApplicationObjectFile -Destination D:\SP\Dest\










come the below message after successfully run the command.













Now check you source path and destination path now created the Table.txt at source path and separate file are created at  destination path.












Thank You.