Monthly Archives: June 2020

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.