The Txt2Al Conversion Tool: How to Export Dynamics NAV objects and converting to AL

Hi Everyone,

In this article, I will show you how you can use Txt2Al conversion tool that is the part of NAV 2018 and Dynamics 365 Business Central On-Premise.

Using this Txt2Al conversion tool you can take existing Dynamics NAV objects that have been exported in .txt format and convert them into the new .al format and use these .al format file directly using Visual Studio Code to develop/build extensions for Dynamics 365 Business Central.

Converting the NAV objects consists of following 2 steps:

1. Exporting the objects from C/SIDE [Either from Development Environment or using PowerShell Command]
2. Converting the objects to the new syntax.

You can find Txt2Al tool in following location if you installed Dynamics 365 Business Central On-Premise on your machine:
C:\Program Files (x86)\Microsoft Dynamics 365 Business Central\130\RoleTailored Client\Txt2Al.exe

Steps to use the Txt2Al conversion tool: Reference
Step 1: Compile you Dynamics NAV DB
Step 2: Export all baseline objects sue following steps: using following command line:
* Create 2 folders in any drive where you want to export NAV objects and want to put converted .al files
* Open Command Prompt as Administrator
* Navigate to C:\Program Files (x86)\Microsoft Dynamics 365 Business Central\130\RoleTailored Client\
command line: CD "C:\Program Files (x86)\Microsoft Dynamics 365 Business Central\130\RoleTailored Client\"
* And execute following command line to export all table object:
finsql.exe Command=ExportToNewSyntax, File=E:\TXT2AL\Tab\AllExportedTableObjects.txt, Database="Demo Database NAV (13-0)", ServerName=.\NAVDEMO ,Filter=Type=table;
* Command prompt should look like:
 
*
 After Successful execution of above command you will get the .txt file that contains all table objects in it

To export specific table object use following command line:
finsql.exe Command=ExportToNewSyntax, File=<path\filename.txt>, Database="<databasename>", ServerName=<servername> ,Filter=Type=table;ID=<tableID>
e.g. finsql.exe Command=ExportToNewSyntax, File=E:\TXT2AL\Tab\exportedNewModifiedObjects.txt, Database="Demo Database NAV (13-0)", ServerName=.\NAVDEMO ,Filter=Type=table;ID=3
Similarly, for
Tables: 
Type= table; ID='50000..50005';
Pages: 
Type= 'page'; ID='50000..50005';
Queries:
Type= 'query'; ID='50000..50005';
Reports:
Type= 'report'; ID='50000..50005';
Menusuite:
Type= 'menusuite'; ID='50000..50005';
XMLPort:
Type= 'xmlport'; ID='50000..50005';
NOTE: TXT2AL requires objects exported in New Syntax


To export all new and/or modified objects use following command line:
finsql.exe Command=ExportToNewSyntax, File=<filename.txt>, Database="<databasename>", ServerName=<servername> ,Filter=Type=table;Modified = Yes
e.g. finsql.exe Command=ExportToNewSyntax, File=E:\TXT2AL\Tab\AllExportedTableObjects.txt, Database="Demo Database NAV (13-0)", ServerName=.\NAVDEMO ,Filter=Type=table;Modified = Yes

 

Step 3: Now use Txt2Al tool to convert the exported object to AL:
Syntax: txt2al --source --target --rename --type --extensionStartId --injectDotNetAddIns --dotNetAddInsPackage --dotNetTypePrefix --translationFormat --addLegacyTranslationInfo
e.g. txt2al --source=E:\TXT2AL\Tab\ --target=E:\TXT2AL\AL\ --rename --extensionStartID 70070000

Now if you go in AL folder you will get the converted AL file:


Sometimes people got confused what does generating delta files means? Reference
You can use the Compare-NAVApplicationObject PowerShell cmdlet to generate .delta files from two versions of a set of application objects. 
The cmdlet has a ExportToNewSyntax switch that allows generating .delta files that can be used as a starting point for creating extensions. Setting the ExportToNewSyntax flag generates .delta files that contain additional information needed to generate the correct structure and layout of extension objects.
Syntax for generating .delta files:
Compare-NAVApplicationObject -OriginalPath "C:\ORIGINAL\OldObjects.txt" -ModifiedPath "C:\MODIFIED\ModifiedObjects.txt" -ExportToNewSyntax

Important Note:
 The Txt2Al conversion tool will reject .delta files that were generated without using the -ExportToNewSyntax flag.

 

I hope this article will help you when you will try to convert Dynamics NAV C-Side object source code to AL.

Stay Tuned!

Add comment