Generate Symbols in a Modern Development environment with Microsoft Dynamics NAV 2018

Original URL…

With the general availability of Microsoft Dynamics NAV 2018 in the first week of December 2017, the new and Modern development environment experience becomes more and more used by developers; side by side with the C/SIDE development environment.

Working with a standard CRONUS database is pretty easy, while every developer would like to give it a spin with their own customized database. In this scenario, it is paramount to have the appropriate symbols generated in order to be successfully pulled out by AL Extension command in Visual Studio Code and develop a custom extension against a proper customized source database.

Installing CSIDE Development Environment side by side with Modern Development Environment is duly described in the docs, as well as how to generate / re-generate symbols. For more information, see https://docs.microsoft.com/en-us/dynamics-nav/developer/devenv-running-cside-and-al-side-by-side.

Here are a few tips that can be helpful when generating symbols.

Anuncios

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!

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.

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

Dynamics NAV 2018 – Running C/SIDE and AL Side-by-Side

URL Original…

Dynamics NAV 2018 supports development using both C/SIDE and AL, as well as the in-client designer side-by-side. When new objects are added or changed in C/SIDE these changes must be reflected in the symbol download in Visual Studio Code using the AL Language extension. To enable this reflection, a new command and argument has been added to finsql.exe called generatesymbolreference, run it as illustrated below.

Get started generating symbols and compiling all objects

Use the generatesymbolreference command specified with the database and server name. This command will add symbol references to the NAV App Object Metadatatable for the specified database.

Important

Run this command at least once to have a set of symbol references.

Syntax example

finsql.exe Command=generatesymbolreference, Database=”Demo Database NAV (11-0)”, ServerName=.\NAVDEMO`

Note

This is a lengthy operation.

Continuously generate symbols each time you compile objects in C/SIDE

Use generatesymbolreference set to yes as a command line argument each time you start finsql.exe to have all compilations add a symbol reference to the NAV App Object Metadata table. The default setting of the argument is no.

Note

If you make changes in C/SIDE and start the C/SIDE development environment without the generatesymbolreference flag set to yes, no symbols will be generated when downloading symbols from Visual Studio Code.

Syntax example

Copy
finsql.exe generatesymbolreference=yes

Dynamics NAV Server setting

In addition, a new Dynamics NAV Server setting has been introduced; Enable Symbol Loading at Server Startup. This setting must be enabled to allow any symbol generation.

If the setting is not enabled, the generatesymbolreference setting does not have any effect.

See Also

Developing Extensions

Microsoft AL – Debugging

Original URL…

The process of finding and correcting errors is called debugging. With Visual Studio Code and the AL Language extension you get an integrated debugger to help you inspect your code to verify that your application can run as expected. You start a debugging session by pressing F5.

Tip

For more information about Debugging in Visual Studio Code, see Debugging.

Important

To enable debugging the NetFx40_LegacySecurityPolicy setting in the Microsoft.Dynamics.Nav.Server.exe.config file must be set to false. This requires a server restart.

For the preview, there are a number of limitations to be aware of:

  • “External code” can only be debugged if the code has the ShowMyCode flag set. For more information, see Security Setting and IP Protection.
  • Not all AL types yet show helpful debugging.
  • The debugger launches a new client instance each time you press F5. If you close the debugging session, and then start a new session, this new session will rely on a new client instance. We recommend that you close the Web client instances when you close a debugging session.
  • And finally, using the debugger with the online sandbox signup and AAD authentication method is not yet supported.

Breakpoints

The basic concept in debugging is the breakpoint, which is a mark that you set on a statement. When the program flow reaches the breakpoint, the debugger stops execution until you instruct it to continue. Without any breakpoints, the code runs without interruption when the debugger is active. Set a breakpoint by using the Debug Menu in Visual Studio Code.

Debugging Shortcuts

Keystroke Action
F5 Start debugging
Ctrl+F5 Start without debugging
Shift+F5 Stop debugging
Ctrl+Shift+F5 Restart debugging
F10 Step over
F11 Step into
Shift+F11 Step out

For more shortcuts, see Debugging.

Programming in AL

Original URL…
AL is the programming language that is used for manipulating data (such as retrieving, inserting and modifying records) in a Dynamics 365 for Finance and Operations, Business edition database, and controlling the execution of the various application objects, such as pages, reports, or codeunits.

With AL, you can create business rules to ensure that the data which is stored in the database is meaningful and consistent with the way customers do business. Through AL programming, you can:
•Add new data or transfer data from one table to another, for example, from a journal table to a ledger table.
•Combine data from multiple tables into one report or display it on one form or page.

Where to write AL code

Almost every object in Dynamics 365 for Finance and Operations, Business edition contains triggers where you can add your AL code. Triggers exist for the following objects:
•Tables
•Table fields
•Pages
•Reports
•Data items
•XMLports
•Queries

You can initiate the execution of your AL code from the following:

•Actions
•Any object that has an instantiation of the object that contains AL code. An example of an instantiation is a variable declaration.

Note:If the AL code is in a local method, then you cannot run it from another object.

Guidelines for placing AL code

We recommend the following guidelines for AL code:
•In general, put the code in codeunits instead of on the object on which it operates. This promotes a clean design and provides the ability to reuse code. It also helps enforce security. For example, typically users do not have direct access to tables that contain sensitive data, such as the General Ledger Entry table, nor do they have permission to modify objects. If you put the code that operates on the general ledger in a codeunit, give the codeunit access to the table, and give the user permission to execute the codeunit, then you will not compromise the security of the table and the user will be able to access the table.
•If you must put code on an object instead of in a codeunit, then put the code as close as possible to the object on which it operates. For example, put code that modifies records in the triggers of the table fields.

Reusing code

Reusing code makes developing applications both faster and easier. More importantly, if you organize your AL code as suggested, your applications will be less prone to errors. By centralizing the code, you will not unintentionally create inconsistencies by performing the same calculation in many places, for example, in several triggers that have the same table field as their source expression. If you have to change the code, you could either forget about some of these triggers or make a mistake when you modify one of them.
Getting Started with AL…

Steps to set up a sandbox environment and Visual Studio Code

Go through the following steps to set up a sandbox environment. With the preview you get sample code that compiles and runs with just a few commands.+

1) Sign up for a Dynamics 365 for Financials sandbox.
2) Download Visual Studio Code.
3) Download the AL Language extension.
4) Press Alt+A, Alt+L to trigger the Go! command, and then choose Cloud.
5) Enter the credentials you provided for the sign up, and then Download symbols.
6) Press F5 to deploy and run the extension on your online sandbox tenant. +

Note+

Use Ctrl+Shift+P to clear the credentials cache if you want to deploy against a different environment.+

You now have a HelloWorld sample that compiles and runs. The JSON files in the project are automatically updated with the settings that allows you to press F5 to build and deploy the solution.+

Note+

If symbols are missing, you will be prompted to download them.+

As this feature is still in preview you might run into unrecoverable issues from time to time. In these cases, use Reset Sandbox to reset the sandbox and start from a clean environment.+

Interested in an on-premise version? It’s just as easy. Just sign up by following these steps.+

1) First, you will need an Azure subscription, sign up for a free subscription.
2) Go to the Developer Preview.
3) When you have a virtual machine set up, you will see a welcome text and here you can choose to try out the developer preview following the instructions on the screen. +

Note+

Build and get inspired by our sample library on GitHub.+

JSON file settings

There are two JSON files in the project; the app.json file and the launch.json file. The files are automatically generated for your project. For more information, see JSON files.+

The symbol file

The symbol file contains metadata of the application. This is what your extension is being built on, and therefore the symbol file must be present. If it is not present, you will be prompted to download it. For more information about the platform symbol file, see Symbols.+

Installing and publishing an extension

To make your extension available to users, the package must be published to a specific Microsoft Dynamics NAV Server instance. The extension can be installed for one or more tenants. For more information about how to install and publish an extension, see How to: Publish and Install an Extension V2.

AL Development Environment…(Samples) – (GitHub).