{"id":18135,"date":"2018-07-30T12:11:24","date_gmt":"2018-07-30T10:11:24","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/nav\/?p=18135"},"modified":"2024-07-26T14:10:26","modified_gmt":"2024-07-26T21:10:26","slug":"developer-preview-july-2018-update","status":"publish","type":"post","link":"https:\/\/www.microsoft.com\/en-us\/dynamics-365\/blog\/it-professional\/2018\/07\/30\/developer-preview-july-2018-update\/","title":{"rendered":"Developer Preview – July 2018 Update"},"content":{"rendered":"\n

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<\/a>.<\/p>\n\n\n\n

This Developer Preview is available only through the Ready to Go program. Read more at\u00a0http:\/\/aka.ms\/readytogo<\/a>. 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.<\/p>\n\n\n\n

OData-bound actions in AL<\/h2>\n\n\n\n

It is now possible to declare OData bound actions in AL. A new attribute [ServiceEnabled]<\/strong> and new AL types WebServiceActionContext<\/strong> and WebServiceActionResultCode<\/strong> have been introduced to achieve this.<\/p>\n\n\n\n

Here is an example of how to declare a new OData bound action on a page exposed as a web service:<\/p>\n\n\n

\n[ServiceEnabled]\nprocedure CreateCustomerCopy(var actionContext : WebServiceActionContext)\n    var\n        createdCustomerGuid : Guid;\n        customer : Record Customer;\n    begin\n        actionContext.SetObjectType(ObjectType::Page);\n        actionContext.SetObjectId(Pages::Customer);\n        actionContext.AddEntityKey(customer.fieldNo(Id), createdCustomerGuid);\n        actionContext.SetResultCode(WebServiceActionResultCode::Created);\nend;\n<\/pre><\/div>\n\n\n

Note that similarly to C\/AL approach the function\u2019s parameter has to be named \u2018actionContext\u2019 to be correctly picked up by the OData framework.<\/p>\n\n\n\n

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<\/a><\/p>\n\n\n\n

Event discovery using a recorder<\/h2>\n\n\n\n

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.<\/p>\n\n\n\n

To get the list of all events raised during a given session use the new\u00a0Event Recorder:<\/strong><\/p>\n\n\n\n

    \n
  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,<\/li>\n\n\n\n
  2. Press the\u00a0Start\u00a0<\/strong>button in order to start recording events.<\/li>\n\n\n\n
  3. Now, perform the actions required for your scenario.<\/li>\n\n\n\n
  4. Press the Stop\u00a0<\/strong>button to get the list of all recorded events.<\/li>\n\n\n\n
  5. Choose the event that suits you the best and get an AL snippet to use in VS Code by choosing Get AL Snippet<\/strong>.<\/li>\n<\/ol>\n\n\n\n
    \"event<\/figure>\n\n\n\n

    Extensible Enums<\/h2>\n\n\n\n

    In this Developer Preview, we’re also adding the ability to add and extend enums. This section introduces the concept.<\/p>\n\n\n\n

    Declaration<\/h3>\n\n\n\n

    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:<\/span><\/p>\n\n\n

    \nenum 50121 Loyalty\n{\n    Extensible = true;\n    value(0; None) { }\n    value(1; Bronze) { }\n    value(4; Silver) { }\n    value(5; Gold)\n    {\n        Caption = \u2018Gold Customer\u2018;\n    }\n}\n<\/pre><\/div>\n\n\n

    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.<\/p>\n\n\n\n

    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:<\/p>\n\n\n

    \nenumextension 50130 LoyaltyWithDiamonds extends Loyalty\n{\n    value(50130; Diamond)\n    {\n        Caption = \u2018Diamond Level\u2018;\n    }\n}\n<\/pre><\/div>\n\n\n

    Usage<\/h3>\n\n\n\n

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

    \nenum Loyalty\n<\/pre><\/div>\n\n\n

    For example, as a table field type:<\/p>\n\n\n

    \nfield(50100; Loyal; enum Loyalty) {}\n<\/pre><\/div>\n\n\n

    Or as a variable:<\/p>\n\n\n

    \nvar\n    LoyaltyLevel: enum Loyalty;\n<\/pre><\/div>\n\n\n

    In C\/SIDE<\/h3>\n\n\n\n

    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.<\/p>\n\n\n\n

    \"Analyzing<\/figure>\n\n\n\n

    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<\/a>. 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.<\/p>\n\n\n\n

    Conversions<\/h3>\n\n\n\n

    Conversions to\/from Enums are more strict than for Options.<\/p>\n\n\n\n