How to convert C/AL based solution to AL using txt2al
Since the launch of Microsoft Dynamics 365 Business Central, a lot of customers are interested in to use 365 BC and along with it, they are also emphasizing to use existing on-premise customization/solutions (or equivalent) on 365 BC as well. Keeping in mind about the customer's demands ISVs and Microsoft Dynamics Partners are in the struggle of upgrading their on-premise solution(s) to cloud based solution in the form of apps/extensions.
At Dynamics 360, along with other services we also provide Microsoft Dynamics NAV & 365 Business Central solutions and to meet the customer demands, the first question always came in mind is, that how can we do this upgrade in the earliest possible time with quality and as per customer demand and need? Do we have any automated tool or defined process? So, the good news is YES, we do have a tool know as txt2al provided by Microsoft, which helps to generate AL code from the existing C/AL (new syntax, will talk about this as well in this post). Isn't amazing? Yes, it is as you don't have to write AL code from the scratch to develop extension(s).
The agenda of this post is to demonstrate that how you can export existing object from Dynamics NAV/365 Business Central on-premise database in new syntax as txt and then from that .txt(.delta) file, how we can generate AL code.
Demo:
For demo purpose I would be using following tools:
- Microsoft Dynamics 365 Business Central (on-premise)
- Command Prompt (cmd)
Setps:
- Run Command Prompt as Administrator
- Change directory to point RTC folder. If you are using Microsoft Dynamics 365 Business Central then your command would be like:
cd C:\Program Files (x86)\Microsoft Dynamics 365 Business Central\130\RoleTailored Client
But if you are using dynamics NAV 2018 then your command would be like:
C:\Program Files (x86)\Microsoft Dynamics NAV\110\RoleTailored Client - Now export the object in new syntax in .txt format using command as follow:
f you are using Microsoft Dynamics 365 Business Central then your command would be like:
finsql.exe Command=ExportToNewSyntax, File="E:\Demo\Modified\RP50000.txt", Database="Demo Database NAV (13-0)", ServerName=.\NAV13 ,Filter=Type=report;ID=50000
But if you are using dynamics NAV 2018 then your command would be like:
finsql.exe Command=ExportToNewSyntax, File="E:\Demo\Modified\RP50000.txt", Database="Demo Database NAV (11-0)", ServerName=.\NAV11 ,Filter=Type=report;ID=50000
In my case: I am exporting Report 50000 which I developed. You need to change the above mentioned command as per your need. You can get more details about finsql parameters from here.
After running the above statement if I go to the specified path in File parameter, E:\Demo\Modified\ I would be able to see a .txt file name as RP50000.txt
If you have multiple objects to export, I suggest to export each object as seperate txt file. I will help you to generate separate .al file for each object - After exporting object, run the following command to convert the C/AL in .txt file into AL.
txt2al --source="E:\Demo\Modified" --target="E:\Demo\AL" --extensionStartId=50000
You can know more about txt2al at: https://docs.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/devenv-txt2al-tool - Now you can use the .al file generated at the path specified in target parameter which is in my case is: E:\Demo\AL
In my next post I would be showing you that how you can use this .al file in your al project and build extension 2.0 using Visual Studio Code.
You can know more about AL development at https://docs.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/devenv-dev-overview
Comments
-
Hi Zaid, When I run the txt2al tool it only returns the help menu. see below Microsoft Windows [Version 10.0.18363.720] (c) 2019 Microsoft Corporation. All rights reserved. C:\Program Files (x86)\Microsoft Dynamics 365 Business Central\140\RoleTailored Client>txt2al --source="G:\PROJECTS\Impax Payroll\Object Conversion\CAL\" --target="G:\PROJECTS\Impax Payroll\Object Conversion\AL\" --rename --extensionStartId=70074000 Copyright (C) 2017 Copyright (c) Microsoft Corporation. All rights reserved. --source=Path Required. The path of the directory containing the TXT files. --target=Path Required. The path of the directory into which the converted AL files will be placed. --rename Rename the output files to prevent clashes with the source .txt files. --type=ObjectType The type of object to convert. Allowed values: Codeunit, Table, Page, Report, Query, XmlPort --extensionStartId The starting numeric ID of the extension objects (Default: 70000000). It will be incremented by 1 for each extension object. --stacktrace Display the stack trace of exceptions raised during the conversion. --fallbackTypeNameResolution Performs a best effort conversion of code that was exported to the new syntax but that might have unresolved references. --injectDotNetAddIns Inject the definition of standard .NET Add-Ins in the resulting .NET package. --dotNetAddInsPackage Inject the definition of .NET Add-Ins from the given .NET package in the resulting .NET package. --multithreaded Run using multiple threads. This improves performance but causes non-repeatable extension numbers and .xlf content. --dotNetTypePrefix Specify a prefix to be used for all .NET type aliases. --translationFormat=ObjectType Specify the format to use when generating translation files. The allowed values are: Xliff, Lcg --addLegacyTranslationInfo Add information to the translation file that can be used to migrate existing translations. --help Display this help screen. C:\Program Files (x86)\Microsoft Dynamics 365 Business Central\140\RoleTailored Client>
*This post is locked for comments