Menu

Generating AL objects from JSON

17. December 2017 - AL, code generation, New Dev Environment, Tobias Fenster, VS Code
This post was originally published on this site

As interacting with WebServices, especially JSON/REST based WebServices, becomes more and more important, it was very good to see that the new NAV dev environment made it quite easy to do exactly that a couple of releases ago. After reading AJ Kauffmann’s excellent blog post on that topic, I had the idea to auto-generate that code based on a JSON file, so that you no longer need to write a single line of code to get a working base structure. With release 2.3.0 of my VS Code extension this is now possible!

For the following steps I assume that you already have an AL project in place. The hello world one, that you can get with command „AL: Go!“ works fine as well. The workflow after installing my extension is as follows:

  1. Hit Ctrl+Shift+P1 and enter „ALR gen“. This will get you the command to call my generation task as VS Code supports partial search in the command palette2. Hit enter to start it
  2. It will now ask you for a URL where it can get the JSON file you want to use. Using a slightly different URL than in AJ’s post you could get the Github issues on NAV on Docker: https://api.github.com/repos/Microsoft/nav-docker/issues
  3. Tell it how you want to name the entity you work with in D365, in our example maybe „Issues“
  4. Very quickly you should get three new files containing a Codeunit with the refresh logic, a Table to handle the data and a Page to display it. Save them to whatever naming convention works for you
  5. As you already have my extension installed, go to the Page you just created and hit Shitf+Alt+P. This will publish your project and run the Page.
  6. You should see an empty list page with an action to refresh the data. Click that action, wait a second and then you should see the data, in our example the NAV on Docker issues

The whole process should look like this:

If you run into problems or have ideas how to improve the extension, please let me know on Github. If you like the extension, rate it or even write a review.

Thanks a lot to AJ Kauffmann for allowing me to build on his code!

The post Generating AL objects from JSON appeared first on Axians Infoma.