Generating AL Objects from JSON

Original URL…

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!

Anuncios

Configuring Visual Studio Code to Use Modern Development Environment with Dynamics NAV 2018

Original URL…

After installing Dynamics NAV 2018, I want to configure Visual Studio Code with Dynamics NAV to use new Development tool.

Before we start lets verify few things and update accordingly.

NDE-1

You can download VS Code from here:-Click to download Visual Studio Code

Install and Launch the Visual Studio Code.

Now Click View -> Extensions.

NDE-2

Click on … to open the extension menu.

Click on Install from VSIX

NDE-3

You can find VSIX file on the installation medium path:

“ModernDev\program files\Microsoft Dynamics NAV\110\Modern Development Environment”

or in the

“C:\Program Files (x86)\Microsoft Dynamics NAV\110\Modern Development Environment”

NDE-4

This will install AL Language Version 0.12.15355

NDE-5

Once the Extension installation is complete, follow below steps

Press Alt+A, Alt+L to trigger the Go! Command

NDE-6

Enter Project Name and Press Enter

NDE-7

Choose “Your own server”

Once you select the “Your own server” you will see a code like below in the “launch.json” file.

NDE-8

Update the information to look similar to below:-

NDE-9

I have updated my ServerInstance as DynamicsNAV110 (you check your instance name if changed while installing server)

I have updated my Authentication as Windows (I am using Windows authentication update what yours use accordingly)

I have added Port as 8049 (please check and use accordingly you are using the port, if using default 7049 then this step not required)

Now save your File. And Press <CTRL + F5>.

NDE-12

Enter your Credentials.

The server url and the web client url are assumed to be the same. That is not the case. The two settings we talked about above, the server url and the developer port number, are the only settings you need in the launch.json.

When VS Code publishes the extension to the NAV server, the NAV server returns the web client url as a response. This url is then opened in the browser. No setting needed in the launch.json at all.

The NAV server reads that setting from the Web Client Base Url server setting.

NDE-13

NDE-11

Your Extension is published, you can verify as below:

NDE-10

Now you are good to go with developing your Extensions using New Modern Development Tool using AL.

HOW DO I: USE VISUAL STUDIO CODE INSTEAD OF SSMS?

Original URL…

Using Visual Studio Code as a replacement for Sql Server Management Studio is very easy. Once you have downloaded and installed VSCode (download it here), you need to add the mssql extension in Visual Studio Code, which you can find here.

Then create a new file in VSCode and give it the extension .sql. The mssql extension enables mssql commands and T-SQL IntelliSense in the editor when the language mode is set to SQL. 

  1. Press CTRL+N. Visual Studio Code opens a new ‘Plain Text’ file by default.
  2. Press CTRL+K,M and change the language mode to SQL.SQL language mode
  3. Alternatively, open an existing file with .sql file extension. The language mode is automatically SQL for files that have the .sql extension.

Then you need to connect to your SQL Server:

  1. In VS Code, press CTRL+SHIFT+P (or F1) to open the Command Palette.
  2. Type sql to display the mssql commands.mssql commands
  3. Select the MS SQL: Connect command. You can simply type sqlcon and press ENTER.
  4. Follow the prompts to specify the connection properties for the new connection profile. After specifying each value, press ENTER to continue.
  5. Verify your connection in the status bar.

Connection status

Now you need to see your databases on your SQL Server. Simply use the following query:

Press CTRL+SHIFT+E to execute the Transact-SQL commands. View the results in the query window.

Then you can query any table in any database, for example:

Press CTRL+SHIFT+E to execute the Transact-SQL commands. View the results in the query window.

On the View menu, select Toggle Editor Group Layout to switch to vertical or horizontal split layout.

Voila, it’s as easy as this!

More information and examples are available here: Use Visual Studio Code to create and run Transact-SQL scripts for SQL Server.

AL Extensions: Importing and Exporting Media Sets

Original URL…

One of the things that has changed when you are building V2 extensions for a cloud environment is that you cannot access most functions that work with physical files.

This presents a bit of a challenge when it comes to working with the media and media set field types, as the typical approach is to have an import and export function so that a user can get pictures in and out of the field.

An example of this is the Customer Picture fact box that’s on the Customer Card:

WorkingWithMediaFields1

As you can see, the import and export functions in C/Side leverage the FileManagement codeunit in order to transfer the picture image to and from a physical picture file. These functions are now blocked.

So…..we have got to take another approach. Enter streams.

Using the in and out stream types we can recreate the import and export functions without using any of the file based functions.

An import function would look like the following. In this example, the Picture field is defined as a Media Set field.

local procedure ImportPicture();
var
   PicInStream: InStream;
   FromFileName: Text;
   OverrideImageQst: Label 'The existing picture will be replaced. Do you want to continue?', Locked = false, MaxLength = 250;
begin
   if Picture.Count > 0 then
      if not Confirm(OverrideImageQst) then
         exit;

   if UploadIntoStream('Import', '', 'All Files (*.*)|*.*', FromFileName, PicInStream) then begin
      Clear(Picture);
      Picture.ImportStream(PicInStream, FromFileName);
      Modify(true);
   end;
end;

The UploadIntoStream function will prompt the user to choose a local picture file, and from there we upload that into an instream. At no point do we ever put the physical file on the server. Also note that the above example will always override any existing picture. You do not have to do this as media sets allow for multiple pictures. I’m just recreating the original example taken from the Customer Picture page.

For the export we have to write a bit more code. When using a Media Set field, we do not have access to any system function that allows us to export to a stream. To deal with this all we need to do is loop through the media set and get each of the corresponding media records. Once we have that then we can export each of those to a stream.

That would look like this:

local procedure ExportPicture();
var
   PicInStream: InStream;
   Index: Integer;
   TenantMedia: Record "Tenant Media";
   FileName: Text;
begin
   if Picture.Count = 0 then
      exit;

   for Index := 1 to Picture.Count do begin
      if TenantMedia.Get(Picture.Item(Index)) then begin
         TenantMedia.calcfields(Content);
         if TenantMedia.Content.HasValue then begin
            FileName := TableCaption + '_Image' + format(Index) + GetTenantMediaFileExtension(TenantMedia);
            TenantMedia.Content.CreateInStream(PicInstream);
            DownloadFromStream(PicInstream, '', '', '', FileName);
         end;
      end;
   end;
end;

We use the DownloadFromStream function to prompt the user to save each of the pictures in the media set. As in our first example, there are no physical files ever created on the server, so we’re cloud friendly!

You may notice that I use the function GetTenantMediaFileExtension in the export example to populate the extension of the picture file. Since the user can upload a variety of picture file types, we need to make sure we create the file using the correct format.

The function to do this is quite simple, however there is no current function in the product to handle it, so you’ll have to build this yourself for now. Hopefully in the near future this function will be added by Microsoft.

local procedure GetTenantMediaFileExtension(var TenantMedia: Record "Tenant Media"): Text;
begin
   case TenantMedia."Mime Type" of
      'image/jpeg' : exit('.jpg');
      'image/png' : exit('.png');
      'image/bmp' : exit('.bmp');
      'image/gif' : exit('.gif');
      'image/tiff' : exit('.tiff');
      'image/wmf' : exit('.wmf');
   end;
end;

NAV Development Preview – December Update

Original URL…

Welcome to our update for the Developer Preview; the December update. As usual, we’ve fixed a lot of issues reported by you, for more information view the list of fixed issues, In addition to that we’re announcing the following changes as you can see listed below. To jump directly to an updated image go to the Azure Gallery sign up at http://aka.ms/navdeveloperpreview.

The AL Formatter

The AL Language Visual Studio Code extension now offers the option of automatically formatting your source code. The auto-formatter can be invoked to format an entire AL document or a pre-selected range.

  • In an existing project, open the document that you want to format, right-click inside the document, and then choose Format Document.
  • To format a range, open the document that you want to modify, select the specific range to format, right-click it, and then choose Format Selection.

Earlier blog posts:

NAV Development Tools Preview – November Update

NAV Development Tools Preview – October Update

NAV Development Tools Preview – September Update

NAV Development Tools Preview – August Update

NAV Development Tools Preview – July Update

NAV Development Tools Preview – June Update

NAV Development Tools Preview – April Update

NAV Development Tools Preview – March Update

NAV Development Tools Preview – February Update

NAV Development Tools Preview – January Update

Announcing the Preview of Modern Development Tools for Dynamics NAV

Configure Visual Studio Code with Dynamics NAV 2018 (Local Server Installation)

Original URL…

After installing Dynamics NAV 2018 I want to configure Visual Studio Code with Dynamics NAV to use new Development tool.

I already had Visual Studio Code installed on my computer (Click to download Visual Studio Code) so I open up the application.

Do not follow Section 01 steps because you will run into issues. Read the Section 02 of the instructions to get it work.

Section 01 :

First thing I want to do is download AL Extention. In order to download AL extension follow below steps:

    • Go to View Menu and click on Extensions.
    • Search for AL 
    • Click Install.

Once the Extention installation is complete I followed below steps:

    • Press Alt+A, Alt+L to trigger the Go! command,
    • Choose “Your own server”
    • Once you select the “Your own server” you will see a code like below in the “launch.json” file.

I change the settings as below :

  "version": "0.2.0",  
   "configurations": [  
     {  
                "type": "al",  
                "request": "launch",  
                "name": "Local server",  
                "server": "http://localhost:7049",  
                "serverInstance": "DynamicsNAV110",  
                "tenant": "default",  
                "authentication": "Windows",  
                "startupObjectId": 22  
     }  
   ]  

 

Once I do that I got an error message, and I could not resolve it. (Could not download symbols. Please see the Visual Studio output log for more details)

Then I thought it is something to do with the Service tier config so I open up the config file and notice that “Enable loading application symbol reference at service startup” is disabled. I enabled it and restart the instance.

Even after that also I could not get to download symbols. Therefore I thought to use a different approach.

Section 02:

I thought to install AL extension manually by using VSIX file.

    • Uninstall AL extention from Visual Studio Code.
    • Click View -> Extention.
    • Click on … to open the extension menu.
    • Click on Install from VSIX

You can find VSIX file on the installation medium path: “ModernDev\program files\Microsoft Dynamics NAV\110\Modern Development Environment” or in the “C:\Program Files (x86)\Microsoft Dynamics NAV\110\Modern Development Environment”

This will install AL Language Version 0.12.15355

Once the Extention installation is complete I follow below steps

    • Press Alt+A, Alt+L to trigger the Go! command.
    • Choose “Your own server”
    • Once you select the “Your own server” you will see a code like below in the “launch.json” file.

   "version": "0.2.0",  
   "configurations": [  
     {  
       "type": "al",  
       "request": "launch",  
       "name": "Your own server",  
       "server": "http://localhost",  
       "serverInstance": "nav",  
       "authentication": "UserPassword",  
       "startupObjectId": 22  
     }  
   ]  

In my local installation, I use Windows Authentication and my NAV instance is different. Therefore I change the file values as below.

    "version": "0.2.0",  
   "configurations": [  
     {  
       "type": "al",  
       "request": "launch",  
       "name": "Your own server",  
       "server": "http://localhost",  
       "serverInstance": "DynamicsNAV110",  
       "authentication": "Windows",  
       "startupObjectId": 22  
     }  
   ]  

Once I update the values and save the file, it successfully downloads the symbols.

Things that made me say “Wow!” about Microsoft Dynamics NAV 2018

Original URL…

After a fair wait (considering we were accustomed to a release every year), and after several rumors about its publication or delay, the new release of Microsoft Dynamics NAV, NAV 2018, includes some interesting features.

My reaction after a first look: Wow!

Although I had seen the Community Technology Preview (CTP) versions of the product, the Release to Manufacturing (RTM) version was a surprise, as it often is. Microsoft (rightly) keeps many details hidden or little documented until the time of release.

The first thing you notice is that now Microsoft, in the product launch documentation (What’s New), always presents the Web Client, while also maintaining the role-tailored client (RTC). As NAV evolves into a cloud-first application, it makes sense now to use only the Web Client or NAV Universal App for mobile devices.  The Web Client has now reached and passed the Windows Client, and most of the features related to user customization work only for the Web Client.

Microsoft has published a full list of new features on PartnerSource, as well as deployment and development documentation. I will review my favorite new features here.

Features for application users

User Personalization & Web Client: It is now possible for users to configure the Web Client individually, treating it like a desktop or interactive whiteboard where they can customize almost everything, including repositioning the Freeze Pane, moving and hiding page parts, repositioning or hiding Cues and Cue Groups, and using ListParts on Role Centers. It’s an awesome look!

PPreview reports on the Web client: Another very helpful feature which enables you to print preview without saving files.

Great Excel integration, with preconfigured Excel reports. The Business Manager and Accounting Role Center has a new option in the ribbon for Excel Reports. Users may select from a dropdown menu of preconfigured reports (see graphic) that is ready to print from Excel. Among those reports are such broadly useful ones as Balance Sheet, Cash Flow Statement and Trial Balance.

Another nice feature is User Tasks, with which you can create tasks to remind you of work to be done, or to assign tasks to yourself or other users (a feature like the CRM Assign function or Service Task). I had submitted this request to MS Connect long ago – nice to see it!

Manage Flows Integration: Embedded Microsoft Flow. Now it is possible to use Microsoft Flow for sales document approval requests.

The Image Analyzer extension uses powerful image analytics provided by the Computer Vision API for Microsoft Cognitive Services to detect attributes in the images. Some examples of its utility are in recognizing a person’s gender or age or identifying items by attributes like type and color.

Features for technical/developer users

There are now two development environments in the installation:

  • the old development environment based on C/SIDE & C/AL
  • the new Modern Development Environment, based on Vs Code+ AL, usable for both NAV 2018 and Tenerife. (See graphic.)

You make your selection in the “Customize the Installation” window during setup (see graphic).

I detail the differences between the two environments in this entry on my Roberto Stefanetti NAV Blog.

Extensions Target Level: Extensions 2.0 publishable/installable: In Extensions 2.0 exists a concept of “levels of extensions,” used to determine the different classifications and capabilities of an extension package. In order the levels progress as follows: Personalization, Extension, Solution, Internal.

In VSCode development, you specify this in the app.json file using the “target” property. This restricts what is allowable within the Extension. On the server side, you have the ability to set the level of 2.0 extensions that you want to allow to be publishable/installable. This enables admins with control over which kinds of Extension they want to have on their systems.

Default & Service Language: NAV Server instance configuration includes two new settings for controlling the Dynamics NAV client language, being:

  • Default Language, which specifies which of the installed Dynamics NAV languages on the server instance will be the default language in the clients
  • Supported Languages, which specifies which of the installed Dynamics NAV languages on the server instance will be available for use in the clients

Change Server Setting Without Restart – Finally! A great feature, as some come configuration changes to the Dynamics NAV Server can be done without a server restart.

Obsolete State for Tables, Fields, and Kays: Table object, fields, and keys include the ObsoleteState and ObsoleteReason properties, used to communicate to developers when a table or key is or will become obsolete.

PowerShell cmdlets: Many new PowerShell cmdlets are now available, both for administering, extensions, development, and deployment. Microsoft provides more detail in this documentation.

Universal App & Windows 10 Continuum: The NAV Universal App for mobile devices is today available on more devices, and a new and interesting feature is Continuum. This technology is a Windows 10 feature that allows you to project your phone to your big screen. You can also interact with keyboard and mouse through Bluetooth, when the connected NAV Universal App is configured to automatically switch to the desktop experience.

ASP.NET Core: The Dynamics NAV web server components now run on ASP.NET Core – cool! ASP.NET Core enables NAV to reach new heights in cloud scalability.

OData V4 Bound Actions: NAV 2018 runs OData web services based on OData V4. OData Relational Query Support provides the ability to include related entities inline within a single OData V4 response. A great feature…all data available in a single call!

Stay tuned for the next wave of updates, and have a nice first experience with NAV 2018!

How to connect Visual Studio Code with NAV 2018

Original URL…

Last couple of days, I got a number of questions from people that all came down to the same issue: how to set the correct settings in the launch.json so Visual Studio Code can connect to NAV 2018. In most cases I saw the same mistake being made. A logical mistake, but also one that leaves you probably wondering why it works that way.

Let’s assume you have enabled the development port in your NAV 2018. Look here to read how that is done.

When you create a new workspace in VS Code with the AL:Go! command, you get by default a launch.json that looks like this:

launch_json_1.png

 

 

Basically the only thing you need to change is the servername. In my case that would be navserver. Some people also change the default developer port 7049 to another port number, let’s say 7149. A common mistake is to put that port number into the server url.

launch_json_2.png

 

Let’s see what happens when we try to download the symbol files.

download_symbols_wrong_port.png

It uses port number 7049! How is that possible?

The port number in the server url is just ignored. Instead you should specify the port number with a separate setting. If that setting is missing, then the default port number 7049 is used. Let’s specify the port number and see what happens.

launch_json_3.png

Let’s download the symbol files again, and watch the url.

download_symbols_correct_port.png

Conclusion: do not specify a port number in the server url. Instead, use the port setting to specify the developer port number.

 

Another common mistake is that the server url and the web client url are assumed to be the same. That is not the case. The two settings we talked about above, the server url and the developer port number, are the only settings you need in the launch.json.

When VS Code publishes the extension to the NAV server, the NAV server returns the web client url as a response. This url is then opened in the browser. No setting needed in the launch.json at all.

The NAV server reads that setting from the Web Client Base Url server setting.

Let’s prove that with an example. In the next screenshot, I set the key to a different value. Sorry, it’s PowerShell, I only have NAV 2018 installed with docker images. 😉

set_publicwebbaseurl.png

How to check the output? Well, I can of course show a browser screen with that url, but would that prove my point? So I figured that a Fiddler trace would probably more convincing. Here is the Fiddler trace when VS Code publishes the extensions to the server.

fiddler_publishnavapp.png

Look at the response, it contains the setting that I did with the PowerShell command.

And here is what happens when the Web Client Base Url is not set:

publish_navapp_error_empty_url.png

I hope this demystifies how VS Code and the NAV server work together!

Development in AL

Original URL…

Extensions are a programming model where functionality is defined as an addition to existing objects and defines how they are different or modify the behavior of the solution. This section explains how you can develop extensions using the development environment for Dynamics 365 for Finance and Operations, Business edition. For an overview of developing apps for Dynamics 365 for Finance and Operations, Business edition, see aka.ms/GetStartedWithApps.

If you’re new to building extensions for Dynamics 365 for Finance and Operations, Business edition, we recommend that you read this document to get an understanding of the basics and terms you will encounter while working. Next, follow the Getting Started with AL to set up the tools.

Understanding objects in the development environment

All functionality in Dynamics 365 for Finance and Operations, Business edition is coded in objects. The extension model is object-based; you create new objects, and extend existing objects depending on what you want your extension to do. Table objects define the table schema that holds data, page objects represent the pages seen in the user interface and codeunits contain code for logical calculations and for the application behavior. These objects are stored as code, known as AL code, and are saved in files with the .al file extension.

Note

A single .al file may contain multiple objects.

There are two other special objects which are specifically used for building extensions. Table extension objects and page extension objects are used for defining additive or overriding changes to table or page objects. For example, an extension for managing a business that sells organic food may define a table extension object for the Item table that contains two additional fields, Organic and Produced Locally. The Organic and Produced Locally fields aren’t usually present in the Item table, but through the table extension these data fields will now be available to store data in and to access from code. You can then use the page extension object to display the fields that you added to the table object.

Note

Extension objects can have a name with a maximum length of 30 characters.

You have several options for creating new objects with the AL Language extension for Visual Studio Code. For more information about the objects that you can create for your extension, see AL Development Environment.

Developing extensions in Visual Studio Code

Using the AL Language extension for Visual Studio Code, you’ll get the benefits of a modern development environment along with seamless publishing and execution integration with your Dynamics 365 for Finance and Operations, Business edition tenant. For more information on getting up and running, see Getting Started with AL.

Visual Studio Code and the AL Language extension lets you do the following tasks:

  • Create new files for your solution
  • Get assistance with creating the appropriate configuration and setting files
  • Use code snippets that provide templates for coding application objects
  • Get compiler validation while coding
  • Press F5 to publish your changes and see your code running

For more information, see Visual Studio Code Docs.

Tip

If you have previous experience working with the C/SIDE development environment and need an overview of some of the changes between the two development environments, see Differences in the Development Environments.

Designer

The Designer works in the client itself allowing design of pages using a drag-and-drop interface. The Designer allows building extensions in the client itself by rearranging fields, adding fields, and previewing the page design. For more information, see Using Designer.

Compiling and deploying

Extensions are compiled as .app package files. The .app package file can be deployed to the Dynamics 365 for Finance and Operations, Business edition server. An .app package contains the various artifacts that deliver the new functionality to the Dynamics 365 for Finance and Operations, Business edition deployment as well as a manifest that specifies the name, publisher, version, and other attributes of the extension. For information about the manifest, see JSON Files.

Submitting your app

When all development and testing is done, you can submit your extension package to AppSource. Before you submit the extension package, we encourage you to read the checklist to help facilitating the validation. For more information, see Checklist for Submitting Your App.

See Also

Getting Started with AL
Keyboard Shortcuts
AL Development Environment