Inserting code snippets in the AX 2012 X++ editor

In the AX 2012 X++ you can quickly insert fragments of code to avoid tedious typing, such as typing for a loop.

To insert a snippet, you must enter the snippets alias (which is usually the first symbol of the code), and press tab. For example, typing switchfollowed by tab, gives you this snippet:
switch ()
    case :
    case :
I don’t have a clear picture of all the available aliases, but these work:
  • switch
  • for
  • do
  • while
  • try
In the regular Visual Studio editor you can add your own code snippets. I haven’t figured out yet, if this is also possible for the X++ editor.
let me explain, how this can be done! The secret to this, is contained within a little known AX 2012 class, called: xppSource

Here we see that we have our cases in which xppSource completion through the use of such code snippets is fired, and also, where you could possibly change this, and / or add your own.

For example, lets change the switch method, within the xppSource class, so that we see really easily that we can make use of this. As you can see below, I’ve added “IDB” to the first case, in the code snippet block.

In saving this, and compiling it, I went back to my previous method, that we see the output from the first screen shot in this post, and performed the switch + tab action. In doing so we now get what you see below.

That’s it! For sure the tag line powerfully simple shows in such a neat little find, which shows giving the ability and flexibility of AX 2012, even for developer needs.