Developer Preview – July 2018 Update

Welcome to the July update of the Developer Preview. With this release, we bring you several new features that help building your solutions as extensions. We also include over 90 resolved GitHub issues. See the list of closed bugs here: https://github.com/Microsoft/AL/milestone/18?closed=1.

This Developer Preview is available only through the Ready to Go program. Read more at http://aka.ms/readytogo. To get all fixes and features described in this post please make sure you are running an image with a build number 13.0.32492.0 or newer.

OData-bound actions in AL

It is now possible to declare OData bound actions in AL. A new attribute [ServiceEnabled] and new AL types WebServiceActionContext and WebServiceActionResultCode have been introduced to achieve this.

Here is an example of how to declare a new OData bound action on a page exposed as a web service:

 

[ServiceEnabled]

procedure CreateCustomerCopy(var actionContext : WebServiceActionContext)

var

createdCustomerGuid : Guid;

customer : Record Customer;

begin

actionContext.SetObjectType(ObjectType::Page);

actionContext.SetObjectId(Pages::Customer);

actionContext.AddEntityKey(customer.fieldNo(Id), createdCustomerGuid);

actionContext.SetResultCode(WebServiceActionResultCode::Created);

end;

 

Note that similarly to C/AL approach the function’s parameter has to be named ‘actionContext’ to be correctly picked up by the OData framework.

More details can be found in Developer and IT-Pro Help here: https://docs.microsoft.com/en-us/dynamics-nav/walkthrough-creating-and-interacting-odata-v4-bound-action

Event discovery using a recorder

A core aspect of creating extensions is to subscribe to events. However, a common challenge is understanding which events are available in a given user flow. Debugging can help, but will only show events already being subscribed to. To aid in the discoverability of events and extension points, there is a new event tracer in the client. With this, a user flow can be recorded to list events that are raised, and the developer can have subscriber code for the event generated for easy copy into AL code.

To get the list of all events raised during a given session use the new Event Recorder:

  1. Navigate to the Event Recorder page using the Search in the client or by using the command ‘AL: Open Events Recorder’ in VS Code,
  2. Press the Start button in order to start recording events.
  3. Now, perform the actions required for your scenario.
  4. Press the Stop button to get the list of all recorded events.
  5. Choose the event that suits you the best and get an AL snippet to use in VS Code by choosing Get AL Snippet.

Extensible Enums

In this Developer Preview, we’re also adding the ability to add and extend enums. This section introduces the concept.

Declaration

Enum is a new concept that over time is meant to replace the existing Option type. It is a new top-level type and is declared like this:

enum 50121 Loyalty

{

Extensible = true;

value(0; None) { }

value(1; Bronze) { }

value(4; Silver) { }

value(5; Gold)

{

Caption = Gold Customer‘;

}

}

Enums require an ID and a name. In the preview the IDs are not validated against any license, but they must be within your assigned object range. An enum contains a list of values. The value corresponds to the individual elements of the OptionString on an Option. The value has an ID and a name. The ID is ordinal value used when persisting the enum and hence they must be unique. The name is used for programmatic access and is a fallback for the caption. Enums are pure metadata and can’t contain any kind of code.

Enums can be marked as extensible. If an enum is extensible; you can add more values to the original list of values. The enumextension syntax looks like this:

 

enumextension 50130 LoyaltyWithDiamonds extends Loyalty

{

value(50130; Diamond)

{

Caption = Diamond Level‘;

}

}

 

Usage

Enums can be used as table fields, global/local variables, and parameters. They are referenced using the following syntax:

enum Loyalty

For example, as a table field type:

field(50100; Loyal; enum Loyalty) {}

Or as a variable:

var

LoyaltyLevel: enum Loyalty;

 

In C/SIDE

Since most of the enums that are currently relevant for extensibility are on table fields in the base-app, we have made it possible to mark a table field in C/SIDE as Extensible.

To extend a table field option you must set up your development environment to run C/SIDE and AL side-by-side as described here: https://docs.microsoft.com/en-us/dynamics-nav/developer/devenv-running-cside-and-al-side-by-side. Once the feature is out of preview we will allow requesting base application enums to be made extensible through GitHub requests similar to event requests.

 

Conversions

Conversions to/from Enums are more strict than for Options.

  • An enum can be assigned/compared to an enum of the same type.
  • To be backwards compatible we support conversion to/from any Option, but we may in the future be more strict.

 

Known Issues in the July preview

  • No runtime checks for ID collisions.
  • Declare C/SIDE enums with the same ID on multiple table option fields will break symbol generation.

 

That’s it for now. As usual we encourage you to let us know how you like working with these additions and keep submitting suggestions and bugs. You can see all the filed bugs on our GitHub issues list (https://github.com/Microsoft/AL/issues).

 

For a list of our previous blog posts, see the links at the end of this post.

Developer Preview – June 2018 Update

Developer Preview – May 2018 Update

Developer Preview – March 2018 Update

NAV Development Tools Preview – February 2018 Update

NAV Development Tools Preview – Anniversary Update

NAV Development Tools Preview – December 2017 Update

NAV Development Tools Preview – November 2017 Update

NAV Development Tools Preview – October 2017 Update

NAV Development Tools Preview – September 2017 Update

NAV Development Tools Preview – August 2017 Update

NAV Development Tools Preview – July 2017 Update

NAV Development Tools Preview – June 2017  Update

NAV Development Tools Preview – April 2017 Update

NAV Development Tools Preview – March 2017 Update

NAV Development Tools Preview – February 2017 Update

NAV Development Tools Preview – January 2017 Update

Announcing the Preview of Modern Development Tools for Dynamics NAV