Solutions
Markets
References
Services
Company
Converting traditional C/AL code to AL (and finally having “where used”)

Converting traditional C/AL code to AL (and finally having “where used”)

23. April 2017

Converting traditional C/AL code to AL (and finally having “where used”)

On Friday a new update of the new development environment for NAV arrived. A number of new features are described here and the in-client designer improvements are really nice but what most caught my attention was the first release of a tool to convert traditional C/AL code to the new AL code. Let’s see what it can already do.

Converting C/AL to AL

My first try was with an object already in the database of the preview Azure image and unsurprisingly that worked fine. I then went on to try with one of our custom objects in our number range. For whatever reason I thought it needed to compile and therefore removed all references to non-Cronus objects to make sure it compiled in the preview image and that also worked fine. But then I thought that because the new environment is completely text-based it possibly didn’t even need the objects to be compilable. And indeed, they don’t! So here is what I did:

  1. Export a custom object (in my case Codeunit 5010307) as text
  2. Import it in the preview database using the regular Dev Environment
  3. Export it again using the new ExportToNewSyntax Command of finsql
  4. Run it through the converter called txt2al
  5. Open the result in Visual Studio Code
  6. Celebrate!

As the documentation in the blog post mentioned above might not work directly for you, here are the commands I used after the well-known initial export and import:

mkdir source
mkdir target
"c:\Program Files (x86)\Microsoft Dynamics NAV\100\RoleTailored Client\finsql.exe" Command=ExportToNewSyntax, File=source\exportedObjects.txt, Database="Demo Database NAV (10-0)", ServerName=.\NAVDEMO ,Filter=Type=codeunit;ID=5010307
"c:\Program Files (x86)\Microsoft Dynamics NAV\100\RoleTailored Client\txt2al.exe" source target -rename
code target

Or see the result here1:

Where used?

I also noticed something I didn’t see in previous releases: All variables and methods have reference counts. To test how this works I converted another object to AL which I knew referenced a number of methods of my first object. Obviously both have a lot of compilation errors as they depend on a lot of other custom objects but I can already show all references similar to the “Peek definition” feature.

Thanks to awesome Visual Studio Code we finally have a “where used” functionality directly in the code editor!2 I know there are a couple of solutions like Prism or OMA out there offering such functionality but from my point of view this is an absolute must-have for a professional editor and you shouldn’t need to buy additional tooling for something like this.

There are a number of other things worth mentioning like the speed of conversion or the speed of compilation. I really like the way this is progressing and very much look forward to using this on a day to day basis.

  1. The additional “timeout 1” is just to wait for finsql to finish exporting the object
  2. I am repeating myself but I know that this may seem strange to someone from outside the NAV world. But there really isn’t something like this in the traditional code editor C/SIDE. And yes it sucks and it definitely is a bit late to implement that feature but better late than never…