Category Archives: Business Central 2020 Wave 1 (On Premises)

How to create functions (procedures in AL)

In this post some examples of how to accomplish things in AL. I’m sharing this because it saves me time if I don’t know anymore how to do certain things.

  • A simple global function
  • A simple local function
  • Global function with OnPrem scope attribute
  • Global function with Cloud scope attribute
  • Local function with parameter list and return value

Simple global function:

procedure GlobalFunction()
var
    Int: Integer;
begin
    Int := 1+1;
    Message(Format(Int));
end;

Simple local function:

local procedure LocalFunction()
var
    Int: Integer;
begin
    Int := 1+2;
    Message(Format(Int));
end;

By default global functions in codeunits for example are available as methods in webservices if the codeunit is published as a webservice. By using the scope attribute a function can still be Public without being available as a webservice method;

  • Global function not available as webservice method
  • Global function available as webservice method

Global function not available as webservice method

[Scope('OnPrem')]
procedure GlobalFunction()
var
    Int: Integer;
begin
    Int := 1+3;
    Message(Format(Int));
end;

Global function available as webservice method: see the default global function. Global functions are by default a webservice method when the object is exposed as a webservice. The scope attribute is by default ‘Cloud’. So specifying is not neccesary:

[Scope('Cloud')]
procedure GlobalFunction()
var
    Int: Integer;
begin
    Int := 1+4;
    Message(Format(Int));
end;

Local function with parameter list and return value could look like this for example:

local procedure SumFunction (x:integer;y:integer) "SumResult" : integer
begin
    Exit(x+y);
end;

Company Badge in Business Central 16

The Company Information table contains a field “System Indicator Style” which is of type Option. Available options can be found in the OptionMembers property:

    field(48; "System Indicator Style"; Option)
    {
        Caption = 'System Indicator Style';
        OptionCaption = 'Standard,Accent1,Accent2,Accent3,Accent4,Accent5,Accent6,Accent7,Accent8,Accent9';
        OptionMembers = Standard,Accent1,Accent2,Accent3,Accent4,Accent5,Accent6,Accent7,Accent8,Accent9;
    }

If you go to ‘page Company Information’ you can set a label that is displayed in the right corner. This is called a Company Badge now and can be configured through the Company Badge Fasttab in the Company Information page:

By default it is not configured. To configure this select Custom and choose a Company Badge Style. You can then enter a company Badge Text with a maximum of 4 characters.

The page values are mapped to Option Values in the table Field System Indicator Style:

Option ValueRepresents color
StandardDark Blue
Accent1Light Blue
Accent2Dark Green
Accent3Light Green
Accent4Dark Yellow
Accent5Light Yellow
Accent6Red
Accent7Orange
Accent8Deep Purple
Accent9Bright Purple
Indicator Field Options mapped to colors (Company Badge in BC)

When configured the results looks as following:

AL Development in Business Central – Part 6 How to create a page extension

To create a page extension you need to define the following things:

An example:

pageextension 50101 "CustomerList Ext" extends "Customer List"
{
    layout
    {
        addafter("No.")
        {
            field(Skilled; Skilled)
            {
                ApplicationArea = All;
                ToolTipML = ENG = 'Specifies whether this customer is skilled and followed training.';
            }
        }
    }
}

If you now open the Customer List the result should look like this. Pretty straightforward isn’t it?

Customize the existing Customer List with a simple Page Extension

AL Development in Business Central – Part 5 How to create a table extension

To create a table extension you need to define the following things:

  • The TableExtension ID and Name
  • Which table to extend
  • The new field ID and Name, DataType, Caption and DataClassification

More information about the DataClassification property can be found on Microsoft Docs: https://docs.microsoft.com/nl-be/dynamics-nav/dataclassification-property

An example:

tableextension 50100 "Customer Extension" extends Customer
{
    fields
    {
        field(50000; Skilled; Boolean)
        {
            DataClassification = ToBeClassified;
        }
    }
}

Don’t forget to extend the relevant pages with the new fields so that users can also see this new field when they open the customer card or customer list. In the post post I will show how to extends the pages and demonstrate how this will look to the user.

AL Development in Business Central – Part 4 More in detail about launch.json and app.json

In your Business Central workspace some configuration files were created and an example AL file (see part 3). In this post we will get into more detail about the configuration files (JSON based).

The AL workspace contains configuration files:

  • launch.json
    • In this file serveral settings are defined like: servername, server instance and startupobject.
    • Located in the .vscode folder
    • Controls debug environment
  • app.json
    • This configuration file serves as a manifest and contains information about your app.
    • Located in the workspace root

An example how the file launch.json looks like by default in BC16:

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "al",
            "request": "launch",
            "name": "Your own server",
            "server": "http://localhost",
            "serverInstance": "BC160",
            "authentication": "Windows",
            "startupObjectId": 22,
            "startupObjectType": "Page",
            "breakOnError": true,
            "launchBrowser": true,
            "enableLongRunningSqlStatements": true,
            "enableSqlInformationDebugger": true
        }
    ]
}

Some more important launch.json settings explained:

SettingDescription
authenticationWindows, AAD (Azure Active Directory) or UserPassword
serverThe url of your server
serverinstanceThe name of the server instance running on your server (BC160 in my case)
startupObjectTypeSpecify the object type. This could be a page or table. In BC16 you also have the possibility to specify Report or Query.
startupObjectIdThe object ID to start when you press [F5]

An app.json looks like this by default:

{
  "id": "45a1ebaf-28ba-4c4b-8b33-24a4df88f1f4",
  "name": "ALProject1",
  "publisher": "Default publisher",
  "version": "1.0.0.0",
  "brief": "",
  "description": "",
  "privacyStatement": "",
  "EULA": "",
  "help": "",
  "url": "",
  "logo": "",
  "dependencies": [
    {
      "id": "63ca2fa4-4f03-4f2b-a480-172fef340d3f",
      "publisher": "Microsoft",
      "name": "System Application",
      "version": "16.0.0.0"
    },
    {
      "id": "437dbf0e-84ff-417a-965d-ed2bb9650972",
      "publisher": "Microsoft",
      "name": "Base Application",
      "version": "16.0.0.0"
    }
  ],
  "screenshots": [],
  "platform": "16.0.0.0",
  "idRanges": [
    {
      "from": 50100,
      "to": 50149
    }
  ],
  "contextSensitiveHelpUrl": "https://ALProject1.com/help/",
  "showMyCode": true,
  "runtime": "5.0"
}

Some app.json settings explained:

SettingDescription
nameThe name of the app
publisherThe publisher of the app
platformVersion of the dependent platform. Version 16 is Business Central 2020 Wave 1.
runtimeThe version of the runtime. At the moment of writing we have 5 major versions of the AL Runtime:
1.0 Business Central April 2018 release
2.0 Business Central October 2018 release CU 2
3.0 Business Central April 2019 release
4.0 Business Central 2019 release wave 2 (BC15)
5.0 Business Central 2020 release wave 1 (BC16)

More detailed information about the JSON configuration file is available here on Microsoft Docs.

AL Development in Business Central – Part 3 (Connect, Download symbols, Extend a page and Publish as extension)

Now that we have VS Code with the required AL Extension we can now connect to the BC environment.

Open VS Code

Pres [F1] in VS Code and type AL:Go! and press the [Enter] key

AL: Go! in VS Code

Accept the default path by pressing [Enter]
Select the target platform ‘5.0’ Business Central 2020 release Wave 1:

Target platform list in VS Code

A new project has now been created (with an app.json file). Select ‘Your own server’ since my posts are based on an on-prem environment, but if you are using BC in the cloud select: Microsoft cloud sandbox (out of scope in this post). Now other files are created in your ‘project folder’, these 2 are the most important: launch.json and settings.json
Locate and click launch.json in the explorer (left pane). You now see the contents of this file. Our default BC installation uses Windows authentication so change the launch.json:

"authentication": "UserPassword", 

to

"authentication": "Windows",

and save the file.

Now download the symbols. Press [F1] and type the command: AL: Download Symbols and press [Enter]. I received an error

Error: Could not connect to the server. Please verify that:1. The server is started.2. The development endpoint is enabled (DeveloperServicesEnabled server setting).3. The service name matches the one specified in the URL.4. The port number matches the one specified in the URL (DeveloperServicesPort server setting).5. The protocol matches the one specified in the URL (DeveloperServicesSSLEnabled server setting), and that a trusted certificate is used in case of an SSL connection.

I enabled DeveloperServices on the service, saved the change and restarted the service and now I was able to download the symbols:

Enable Developer Service Endpoint in the Busines Central Administration Tool

If you couldn’t download the symbols don’t proceed. All further steps will fail until you resolve the issue. If the symbol download was successful you should see a message in the output pane:

Open HelloWorld.al in the VS Code explorer (Left Pane) and change the message to something else.
Publish the file (which in fact is a page extension). Press [F5]. In my scenario the publish failed due to an error:

Error: Could not open the specified startup page. Please check that the server configuration key PublicWebBaseUrl has been properly set.

So after checking this key I filled in the WebBaseUrl saved it and restarted the BC service:

Tip: it’s also possible to change this setting by using PowerShell.

Web Client Base URL setting in the Administration Tool

The publish still errored. So I closed VS Code and published it again. It now executed without any problems and our first extension is published:

You will see this message (extension) when you open the customer card in Business Central

AL Development in Business Central – Part 2 (Install VS Code + AL Dev Extension)

In order to customize or extend Business Central you need the AL Language Extension and Visual Studio code. To get started with AL follow these steps:

Download Visual Studio Code and install it (I used version 1.44). After downloading, run the setup, Next, Next, Next, Next, Install and VS Code is installed in a few seconds.
Download AL Language Extension by clicking on Install. In the popup screen now click on Continue. Now click Allow to open the al file in VS Code.

Tip: on the BC Application Server the extension is also available but VS Code won’t update it automatically. A big advantage of downloading the extension is that VS Code will automatically update it if there are updates.

Open AL file in VS Code from the browser (Internet Explorer)

VS Code is now opened with the Extension you selected. Now click the green Install button.

Install AL Language extension for VS Code

After installing select AL as the File Icon theme:

Select File Icon Theme

Now that this extension is installed you can get started. Basic functionalities at your disposal:

  • IntelliSense (Ctrl+Space) for editing, syntax highlighting, formatting
  • Type AL:Go! in the command palette (Ctrl+Shift+P)
  • Support for snippets to easily create objects like code units, pages, etc.
  • Support for finding all references (Shift+F12) to list all instances of a specific symbol
  • Added native support for using HTTP and JSON types to access Azure functions and other Web Services
  • Use Ctrl+F5 to deploy to the current development instance and use F5 to deploy and debug
  • Use Ctrl+Alt+F5 to perform rapid application development (RAD) and use Alt+F5 to perform RAD and debugging

More information about developing in AL can be found on https://docs.microsoft.com/en-us/dynamics365/business-central/dev-itpro/

AL Development in Business Central – Part 1 (High Level Steps)

Because we are working from scratch to create an extension, the following steps should be performed. And before going in detail in my opinion it’s important to first understand what we are really going to do before the ‘how’. In high level the following steps are going to be explained:

Part 2 of this series:
* Open VS Code (with the AL Language extension installed)

Part 3 of this series:
* Run AL:Go!
* Specify server connection in json file
* Download symbols
* Write AL code
* Publish

Part 4 of this series:
* Explain more in detail the configuration files (app.json and launch.json) we used in Part 3.

Part 5 of this series:
* How to create a table-extension

Part 6:
* How to create a page extension

In the upcoming posts I will focus more on these high level steps.

How-to Upload the FLF license file

Run the ‘Business Central Administration Shell’ as Administrator. You can find this ‘tool’ on the server where the Business Central Server Instance is running. It looks like this:

Now type:

Export-NAVServerLicenseInformation -ServerInstance BC160

to view the current license information:

If you have a new license file you can upload this by using the Cmdlet:

Import-NAVServerLicense -ServerInstance BC160 -LicenseFile "C:\Users\Administrator\Documents\BC16License.flf"

Finally, restart the service mentioned. In this example this is BC160. This can also be accomplished by PowerShell:

Set-NAVServerInstance -ServerInstance BC160 -Restart

Please take into consideration that all users, services connected to this service will lose the connection to BC16 (Business Central 2020 Wave 1). Don’t run this cmdlet in a production environment if you don’t know what the real impact is!

How-to Start BC16 Client (Business Central 2020 Wave 1)

If you’ve managed to install BC16 (Business Central 2020 Wave 1) like I wrote in my previous post the next step is to check if everything is ‘really working’ by starting the client. Start the web browser and go to http://localhost:8080/BC160/ on the machine where you also performed the installation. You should now see Business Central:

Tip: always check the system requirements. Microsoft recommends Edge, Chrome, Firefox, or Safari. Internet Explorer 11 is still supported though.

Tip: if you get an error in your browser than maybe setup didn’t finish with success and then this ‘component’ (IIS Application) could be corrupt or not installed at all. Or you could be using the wrong Url or port if you changed some parameters in the setup. If you have problems review your configuration in IIS Manager: