You might already have seen my session on DynamicsCon about Design Patterns. During that session, I mentioned a tool “mdAL”. If not .. well, here it is (starting at the mdAL part):
This tool has seen some major updates – time to blog about it. ;-).
I am not the developer of this tool – so not a single credit should go my way. The main developer of this tool is Jonathan Neugebauer, a German genius who made this for his master thesis, and who is putting this out there for free for us to benefit from. And I promise: we can benefit from this .. a lot! I just discovered this tool by chance (basically Jonathan contacted me through my blog for a review) – and since I have been working on the very similar thing 18 years ago (VB.Net, generating code from Rational Rose (UML) models – don’t ask .. ), I was immediately hooked and saw immense potential!
To understand the goal of the tool, you need to understand what is meant with “Model Driven engineering”: it is a methodology that focuses on creating and exploiting domain models (let’s call it “design patterns”), which are conceptual models of all the topics related to a specific problem.
Indeed .. I got that from Wikipedia ;-).
Let me try to explain this by means of some …
1- We want to create master entities where we implement the default stuff, like number series. A lot of this code is based on a pre-existing “model” of how to implement No. Series. Just imagine this can be generated in minutes…
2- We have a posting routine, based on a master table and documents. So we need journal, ledger entries, register, document tables, … and the codeunits for the posting routine. Every time quite the same, but a bit different. What we did in the old days: copy “Resource Journal” and all its codeunits, and start renumbering and renaming ;-). Just imagine this can be generated in a few minutes…
As you have seen in the video, all this is possible today, in AL, in minutes. Jonathan’s ultimate goal was to have a model driven AL, which basically means: you don’t write code anymore, you basically model it in an understandable language, and the code is generated for you.
Today, the tool has had a major upgrade, and now you can spit out code, without the necessity to have a full model. Basically meaning: you can now use it also as a pure code generator. In my opinion, this makes its functionality even more useful for the community!
The tool can be found on the VSCode marketplace here: mdAL – Visual Studio Marketplace. Please take some time to read through the comprehensive documentation he has provided as well here: mdAL (mdal-lang.github.io). It’s not long, and it’s well worth the read! It explains how to install it, a quick start, the snippets (yes, it has snippets – it’s not even going to be minutes, it could be just seconds ), and so on.
This is an mdal-file with a description of my master-object “Container”. All this can be created with mdAL-snippets – so this really is just a matter of seconds. Very readable:
Then, we simply “Generate AL Code”
And as a result, you’ll get compile-able code in many objects, with many models implemented. The generated code can be found in the src-gen folder:
How awesome is this? Don’t need comments? Remove it! Don’t need No. Series? Remove it!
Oh – did I forget to add “Dimensions” into the equation? Hold my beer…
Done! 2 seconds.Result: we now have Dimension fields and code where necessary, like:
And even with events:
Not enough? Then let’s now take it to a whole other level. Posting routines and documents. Consider this:
I agree – it’s too simple, I need more fields – but look what happens when you generate code. All these files were generated:
Just too much to mention.
My conclusion is simple: this is going to save us a crapload of time! Even if you “just” need some master table and some sub tables (yes, sub-entities are possible as well!). In my opinion it’s an unmatched level of code generation in our Business Central Development world. This is going into the extension pack! My recommendation: play with it! Get used to it! Give feedback to it if you have any! And once you’re comfortable with it – thank Jonathan! ;-).