«

»

Print this Post

Convert C/AL Objects to AL with PowerShell

If you are a NAV developer, you probably have heard about the upcoming “New Developer Tools”. And if you didn’t, it’s very much time for you to catch up with the readings about this, like:

And when you read this blog from Freddy – you might as well got started in Extensionsv1, and wonder how you can convert all your work to Extensionv2 – or basically – from C/AL to AL.

“The Converter”first

Well, the latest update of the NAV Developer Preview has been released (you should read all about it here), and along with that release, we got the very first version of what is going to be the “converter” – the tool that will convert exported txt-files to .al-files.

No PowerShell

I was hoping for a simple extra PowerShell CmdLet, part of the “Microsoft.Dynamics.Nav.Model.Tools” module – or any other. But no .. no PowerShell.

And while some might still think that “PowerShell” is a “step back” – well – for this tool, we actually need to take a step back. This tool has to be executed in .. uhm .. are you sitting down? .. If not .. brace yourself .. In order to use this tool .. we need to use .. the command line.

PowerShell

I actually refuse to take that step back. If you know me a little – I’ll try to make it easy on myself – and make it part of my toolset that I’m comfortable using.

And I really didn’t want to put too much time in it – so I only created a draft version – which tend to work quite well (the reason is that I do expect Microsoft to come up with a PowerShell version of this tool as well).

I remembered that back in version 2013, when we didn’t have the out-of-the-box function “Export-NAVApplicationObject”, that I created some functions in PowerShell to do just that. It was basically a wrapper around the existing command line option to export objects, using the finsql.

I decided to copy most of that business logic into a new function, and extend it with also calling the new txt2al.exe (which you can find also in the “RoleTailored Client” folder – at least in the current TENERIFE version). The end-result is a somewhat-messy-but-it-does-the-trick-function that I decided to call “Export-NAVALfromNAVApplicationObject“. You can find it on my github.

The flow

And this is basically how it works:

  1. First I need to export the objects from a certain database, identified by the serverinstance. But I can’t use the default function for that, I need something else, because Microsoft introduced a new “command” to the finsql that I need to call. While the out-of-the-box command uses the “exportobjects” command, in this case, I need the “ExportToNewSyntax”.
  2. When exported, I need to split the objects. Basically, because I might have exported multiple objects, and I need to convert all of them to individual .al files :-). But also because the txt2al.exe expects a source-folder, and not a source-file.. .
  3. As last step, I call the txt2al.exe, and convert all the files to the result-directory .. and show this directory (either in VSCode or just in a file explorer)

And here is how you can use it…

Just try for yourself .. here is an example which you can execute straight on the NAV Developer Preview VM. It installs my modules, and executes the conversion for all “wizards” in the database of the ServerInstance “NAV”, and shows the converted files in VSCode:

 

 

Happy days 🙂

5.00 avg. rating (98% score) - 3 votes

Permanent link to this article: http://www.waldo.be/2017/05/05/convert-cal-objects-to-al-with-powershell/

1 comment

2 pings

  1. Dmitry Katson

    Great work, very helpful!

  1. AL with VSCode: ExportToNewSyntax » waldo's blog

    […] Convert C/AL Objects to AL with PowerShell […]

  2. AL with VSCode: ExportToNewSyntax - Waldo's Blog - Microsoft Dynamics NAV - Dynamics NAV Users - DUG

    […] that is being done, is described in multiple places. Let me just reference to this post on my blog to get you going on it […]

Leave a Reply

%d bloggers like this: