AL Language extension for Microsoft Dynamics 365 Business Central version 15.0.1433841 (New version)

[ESP] En el siguiente enlace puedes ver leer los cambios relacionados a la versión vigente:

[ENG] En el siguiente link, you can read the changes related to the current version:


15.0

Implicit conversion between Record and RecordRef

We have introduced support for implicit conversion between Record and RecordRef instances, allowing direct assignment between these types.

codeunit 10 RecordAndRecordRefConversion
{

    procedure RecordToRecordRef()
    var
        Customer: Record Customer;
        RecRef: RecordRef;
    begin
        RecRef := Customer;      // Similar to RecRef.GetTable(Customer);
        ProcessRecord(Customer); // Argument conversion
    end;

    procedure RecordRefToRecord()
    var
        Customer: Record Customer;
        RecRef: RecordRef;
    begin
        Customer := RecRef;      // Similar to RecRef.SetTable(Customer); This will cause an error if the table is different
        ProcessCustomer(RecRef); // Argument conversion.
    end;

    procedure ProcessCustomer(r: record Customer)
    begin
        Message('Process Customer');
    end;

    procedure ProcessRecord(rr: RecordRef)
    var
        Customer: record Customer;
    begin
        case rr.Number of
            Database::Customer:
                Message('Process Customer');
            else
                Error('Unable to process record');
        end;
    end;
}

Mocking HTTP calls in AL tests

We have introduced a new handler type HttpClientHandler to allow mocking the response of HTTP requests in test codeunits. This feature allows for more controlled and easier testing of modules that interact with external services. The feature is limited to OnPrem instances only.

HttpClientHandler

When an HttpClientHandler is added to a test method, every HTTP request that occurs during the execution of that test will be intercepted and routed to the handler. The handler method signature is as follows: it receives a TestHttpRequestMessage that contains information about the HTTP request, as well as a TestHttpResponseMessage that contains the mocked HTTP response values that should be updated by the handler. The Boolean return value indicates whether to fall through and issue the original HTTP request (true) or to use the mocked response (false).

TestHttpRequestPolicy Property

We have also introduced a new property on test codeunits called TestHttpRequestPolicy. This property determines how outbound HTTP requests are treated during test execution and has the following possible values:

  • BlockOutboundRequests: Any HTTP request issued during the test execution that is not caught and handled by an HTTP client handler will raise an exception.
  • AllowOutboundFromHandler: All HTTP requests issued during the test execution are required to be caught by an HTTP client handler. The handler is allowed to explicitly fall through to issue the original request to the external endpoint.
  • AllowAllOutboundRequests: All outbound HTTP requests issued during the test execution are allowed.

Example code

codeunit 10 MyCodeunit
{
    procedure MethodWithHttpRequest()
    var
        Client: HttpClient;
        Response: HttpResponseMessage;
    begin
        Client.Get('http://example.com/', Response);
    end;
}

codeunit 11 MyCodeunitTests
{
    Subtype = Test;
    TestHttpRequestPolicy = AllowOutboundFromHandler;

    [Test]
    [HandlerFunctions('HttpClientHandler')]
    procedure TestUnauthorizedResponseHandled()
    var
        MyCodeunit: Codeunit "MyCodeunit";
    begin
        MyCodeunit.MethodWithHttpRequest();
    end;

    [HttpClientHandler]
    procedure HttpClientHandler(request: TestHttpRequestMessage; var response: TestHttpResponseMessage): Boolean
    begin
        // Mock a '401 Unauthorized' response for the 'GET http://example.com/' request
        if (request.RequestType = HttpRequestType::Get) and (request.Path = 'http://example.com/') then begin
            response.HttpStatusCode := 401;
            response.ReasonPhrase := 'Unauthorized';
            exit(false); // Use the mocked response
        end;

        // Fall through and issue the original request in case of other requests
        exit(true);
    end;
}

Searchable downloaded symbols and using them as context in Copilot Chat

Objects from downloaded symbol packages can now be added as context when using the Github Copilot Chat extension (prerelease version 0.24.2024121201) and Visual Studio Code Insiders (version 1.97 and later). It will also be possible to search and navigate to objects coming from downloaded symbol packages via the ‘Open Symbol by Name’ functionality (Ctrl + T). Additionally, the performance of searching workspace symbols has been improved to support the now larger amount of available symbols.

UserControlHost PageType

We have introduced a new PageType UserControlHost. This page type can be used to only render a single usercontrol in the client. With the UserControlHost page type, the layout is optimized by the client to maximize the available space for the usercontrol.

This new page can only have a single control of type usercontrol within the layout Content area.

Actions cannot be specified on this page, and limited properties and triggers are available for it. It is also not extensible.

Multiline strings

AL now has support for multiline string literals. A multiline string must be prefixed with @.

var
    t: Text;
begin
    t := @'This is
a
multiline
string
';
end;

Continue statement

From runtime version 15, it is possible to use the continue keyword in loops to continue to the next iteration.

Preview support in File

Two new methods to open and view a file on the client.

[Ok :=] File.ViewFromStream(Stream: InStream, FileName: String [, AllowDownloadAndPrint: Boolean]);
[Ok :=] File.View(FilePath: String [, AllowDownloadAndPrint: Boolean]);

New methods access properties and array elements

We have improved the API for accessing JSON data with a new set of methods that will avoid always to read data through a JsonToken.

For JsonObject instances we have added:

value := GetBoolean(Key: Text [; DefaultIfNotFound: Boolean])
value := GetByte(Key: Text [; DefaultIfNotFound: Boolean])
value := GetChar(Key: Text [; DefaultIfNotFound: Boolean])
value := GetInteger(Key: Text [; DefaultIfNotFound: Boolean])
value := GetBigInteger(Key: Text [; DefaultIfNotFound: Boolean])
value := GetDecimal(Key: Text [; DefaultIfNotFound: Boolean])
value := GetOption(Key: Text [; DefaultIfNotFound: Boolean])
value := GetDateTime(Key: Text [; DefaultIfNotFound: Boolean])
value := GetDate(Key: Text [; DefaultIfNotFound: Boolean])
value := GetTime(Key: Text [; DefaultIfNotFound: Boolean])
value := GetDuration(Key: Text [; DefaultIfNotFound: Boolean])
value := GetText(Key: Text [; DefaultIfNotFound: Boolean])
value := GetArray(Key: Text [; DefaultIfNotFound: Boolean])
value := GetObject(Key: Text [; DefaultIfNotFound: Boolean])

For JsonArray instances we have added:

value := GetBoolean(Index: Integer [; DefaultIfNotFound: Boolean])
value := GetByte(Index: Integer [; DefaultIfNotFound: Boolean])
value := GetChar(Index: Integer [; DefaultIfNotFound: Boolean])
value := GetInteger(Index: Integer [; DefaultIfNotFound: Boolean])
value := GetBigInteger(Index: Integer [; DefaultIfNotFound: Boolean])
value := GetDecimal(Index: Integer [; DefaultIfNotFound: Boolean])
value := GetOption(Index: Integer [; DefaultIfNotFound: Boolean])
value := GetDateTime(Index: Integer [; DefaultIfNotFound: Boolean])
value := GetDate(Index: Integer [; DefaultIfNotFound: Boolean])
value := GetTime(Index: Integer [; DefaultIfNotFound: Boolean])
value := GetDuration(Index: Integer [; DefaultIfNotFound: Boolean])
value := GetText(Index: Integer [; DefaultIfNotFound: Boolean])
value := GetArray(Index: Integer [; DefaultIfNotFound: Boolean])
value := GetObject(Index: Integer [; DefaultIfNtFound: Boolean])    

New Command in VSCode to start a new project from a template

We have added a new command AL.NewProject. From this it is possible to start a new project from a template.

New IncStr method overload

A new overload of the IncStr method was added to support an arbitrary positive increment. This allows for incrementing number series or other similar series by more than one position in one go.

New VS Code actions from the Web Client

Two new actions have been added to the Extension Management page. One to generate launch configurations in your local AL project to match the environment, and another to select installed extensions and download them as dependencies.

Github Issues

AppSourceCop

PerTenantExtensionCop rules

Reporting

HttpClient

Miscellaneous


Más información / More information:

Deja un comentario