#NAVdevTips 14: From C/AL to AL – how to use Txt2Al tool
I got the task for one of my customers: create standard report copy and do small changes to it. Because I needed to do it in AL I decided to export the object from Database in txt format and then convert it with tool Txt2Al. What was the effect and how it went? You can read below.
What is Txt2Al?
I think very good definition is on Microsoft Docs: “The Txt2Al conversion tool allows you to take existing Dynamics NAV objects that have been exported in .txt format and convert them into the new .al format.” (more about it you can find here: https://docs.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/devenv-txt2al-tool).
How to do it?
Ok so the theory is easy let’s export the txt file. But because we need to use [-ExportToNewSyntax] parameter we will use Development Shell for that. Below function can be used to export report 594 to local folder C:\test\:
Export-NAVApplicationObject ‘Demo Database NAV (11-0)’ C:\test\REP594.txt -Filter ‘Type=Report;Id=594’ -ExportToNewSyntax
Next we run the Txt2Al.exe from command line. We should specify where the file is stored and where we want to export AL file. In example below our file is stored in C:\test\x and it will be exported to C:\test.
And you are now happy owner of brand new file with extension al.
Let’s be honest: do not expect that the objects are ready to use from just after conversion
Below you will find examples what I needed to do to convert the Report 594 to AL. There are few errors which I got – ok if more than 100 is few then yes I had few…
Captions and Labels
First thing which you will see are captions. Still in the file you will find CaptionML and ENU instead simple Caption. So to align with development already done we will need to rid of all such cases first.
And also Text Constants are not converted to Labels.
Table Numbers instead of Name
Secondly, in my report, I needed to change Table Number to Table Name in each place.
Another thing you also can see on the screen below is that if field had space then “” were missing. This one was only in report DataItem properties and in the code was correct however also there were quite a lot of places where I needed to correct such issues.
Also later you can have issue because in the code DataItem table is used instead of it’s name. As you see that also need to be changed.
Instead True/False – Yes/No
I also faced issue related to boolean in “where” statements – they were not converted to False/True value.
Lowercase – not exactly
At the end something which is not an issue if you want to compile your code. But it something which irritates me and for sure will not pass my internal code review – everything here is BIG. Even if Microsoft says: “Use all lowercase letters for reserved language keywords. Built-in methods and types are not included in this rule because they are written using Pascal case”.
So at the end we get object which looks completely different comparing to all other objects.
Use it or not?
Of course use it!!! If you have 100s of objects for sure it will be much more faster to use the tool provided. However if you need to tell your Project Manager or any other person who wants to know how much will take to move your solution from C/AL to AL then think twice about estimates. Because you may be surprised at the end that it not goes so smoothly as you planned.
Also you need to know that there are things that cannot be converted by this tool so you can end up with manually creating files.
I also strongly recommend to visit https://github.com/Microsoft/AL/issues?page=3&q=txt2al&utf8=%E2%9C%93 to check which issues were reported for the tool and to see that Microsoft is still working on it which also is great.