Wednesday 9 January 2019

What is Extension?

Extensions enable us to modify Dynamics 365 Business Central system without directly altering the source resources, making it easier to deploy, manage, and upgrade customizations or extensions. Extension objects can have a name with a maximum length of 30 characters. These objects are stored as code, known as AL code, and are saved in files with the .al file extension. Extensions use Events to interface with Dynamics 365 Business Central. Use of Extensions makes it impossible for outside developers to change the code, or for anyone to see the code. Only code that has been written using one of the Events (hooks) can be rolled up as an Extension. The purpose of using extension is to get away from modifying base code to ease the burden of future upgrades. Extension can be used to customize a system without modifying the source code

Extensions are a new feature that enables partners, ISVs, and customers to customize and extend Dynamics 365 Business Central, without directly altering the source code. We can use Extensions to deliver customizations and extensions, making upgrades seamless and providing the functionality to best suits users’ needs.  

Distributed via an Extensions “Package” file, Extensions can easily be installed or uninstalled, giving complete control over the additional functionality that they need. A full suite of new cmdlets to manage Extensions is provided in the Administrative Shell. Because the source code is not directly modified, Extensions are also easily upgraded, eliminating code merging.

An Extension is an installable feature of Dynamics 365 Business Central functionality built in a way that does not directly alter source resources and distributed as a preconfigured package. Their capability can span from simple UI (User Interface) modifications to complete offerings, such as credit card processing or vertical functionality.

Extensions are designed to be easily upgradable, addressing a partner challenge when multiple solutions are in play. Furthermore, they run on a per tenant basis in the hosted model, providing greater choice for the customer.

Benefits of Using Extensions in Dynamics 365 Business Central include:

Easy to install to your deployment 

Easy to upgrade – Simply install a new Extension version as part of the upgrade process and it takes care of itself. Or upgrade an Extension independently, without a full system upgrade 

Easy to uninstall – Extensions are easy to remove and you have the option to archive the data from the Extension when uninstalling or upgrading 

To further illustrate Extension in Dynamics 365 Business Central, below is an example

Publish :  Places an Extension package into the system, similar to registering it.

Install : Install does what it takes to make the Extension work, for example, adding code or database columns.

Upgrade : Upgrade is simplified. Uninstall the old and install the new version.

Uninstall : Uninstall removes the Extension so that the end user can no longer see or use it. Admins can still reinstall it.

Unpublish : Unpublish physically removes the Extension from the system


Getting Started with AL
To get started writing extensions for Dynamics 365 Business Central you will need a Dynamics 365 Business Central tenant, Visual Studio Code, and the AL Language extension. Visual Studio Code is a cross platform editor that you will use for coding and debugging.


Installing and Publishing an extension
To make your extension available to users, the package must be published to a specific Dynamics 365 Business Central Server instance. The extension can be installed for one or more tenants

The Setup and Extensions button provides a single place for settings. This new set of options has been added for the Business Manager and Accountant Role Centers. From the list of actions, you can open setup pages, either assisted or manual, and you can open setup pages for service connections and extensions. Third-party extension providers can add their actions to the list.

In the Manual Setup action group, each action refers to an area, such as General, Finance, and System. The row for each setup page has keywords allowing you to both search across setup pages and to filter the list to only see setup pages within a given area.

“Extensions will bring a whole new level to Dynamics NAV solution, this is one of the long waited functionality by both customers and partners. It is currently still very limited, it holds a bright future for further developments in Dynamics 365 Business Central. 


Integration API
To empower developers and service providers to easily integrate with Dynamics 365 Business Central, Microsoft is adding a REST API based on web services with easy-to-use authentication.

The entities in the API can be used on their own or in combination with extensions when there is a need to add user interface elements or business logic Dynamics 365 Business Central. The first iteration of the API publishes common record types, including company information, customer, vendor, employee, item (product), sales order, sales invoice, account, and journal.


Modern Client
Business Central will support only the modern client and will only allow for development of customizations and solutions in AL through VS Code. Modern client portfolio includes the primary web-based interface for multiple browser, mobile apps for Android and iPhone/iPad, a Windows 10 App for desktop, plugins for Excel and Outlook, and Power Platform connectors.


AL Progamming
AL is the programming language that is used for manipulating data (such as retrieving, inserting, and modifying records) in a Dynamics 365 Business Central database, and controlling the execution of the various application objects, such as pages, reports, or codeunits.
With AL, we can create business rules to ensure that the data which is stored in the database is meaningful and consistent with the way customers do business. Through AL programming, we can:
  • Add new data or transfer data from one table to another, for example, from a journal table to a ledger table.
  • Combine data from multiple tables into one report or display it on one form or page.

Where to write AL code
Almost every object in Dynamics 365 Business Central contains triggers where you can add your AL code. Triggers exist for the following objects: 
  • Tables
  • Table fields
  • Pages
  • Reports
  • Data items
  • XMLports
  • Queries
The Visual Studio Code editor will become the preferred way of doing modifications in the future and all extensions for Dynamics NAV will be done in Visual Studio. Microsoft has mentioned that in the future, they will be adding support for XML Ports, Queries and Reports in Visual Studio Code.



AL language code sample in Visual Studio for developing extensions for Dynamics NAV
Microsoft has released AL language code samples for developing extensions for Dynamics NAV. This AL sample code is available to download from the following link: https://github.com/Microsoft/AL. Now all the development will be done on Visual Studio using AL code. Hence, programming for developing extensions for Dynamics 365 Business Central has to be done in Visual Studio.


AL sample code for developing extensions for Business Central in Visual Studio.


Prerequisite:
Visual Studio

Purpose:
To understand AL language code sample for developing extensions for Business Central in Visual Studio.


Explanation:
The new version of extensions will be called ‘Extensions 2.0’ which is not based on the Delta file design. With Extensions 2.0, developers need to code and write new objects that describe additional capabilities required in the system. ‘Table Extension’ and ‘Page Extension’ objects will be used to describe new fields and UI elements and ‘in-client page designer’ will be used to make those changes in a WYSIWIG way-all of which are stored as extensions under the cover.

This is referred from the following link:
https://blogs.msdn.microsoft.com/nav/2016/12/13/more-information-about-the-developer-preview-for-dynamics-nav/

In the AL sample code released by Microsoft, there are three .al files i.e. HelloWorld.al, GreetingsManagement.al and CustomerCardExtension.al and two .json files i.e. launch.json and app.json.

CustomerCardExtension.al and HelloWorld.al are adding an action on Customer Card page. CustomerCardExtension.al is a ‘pageextension’ object type. The RunObject property of CustomerCardExtension.al calls HelloWorld.al which is a codeunit object.




Fig. 1: CustomerCardExtension.al calls the Codeunit HelloWorld.al


The keyword extends tells the compiler that this object is extending an existing object that is named after.
On clicking this new action which is created on Customer Card page, Codeunit GreetingsManagement.al runs and generates a greeting message. GreetingsManagement.al is a codeunit for creating random greetings.




Fig. 2: Codeunit GreetingsManagment.al
While creating extensions in the previous way, manifest file has to be generated using Windows PowerShell ISE which is done after creating delta files. But while using AL code for developing extensions for Dynamics NAV in Visual Studio, ‘app.json’ file is required. ‘app.json’ is a manifest file that defines how your code should be built and bootstrapped into a live application. It enables developers to define their applications’ details, setup configurations and runtime environments in a structured way.



Fig. 3: app.json
To debug your app in VS Code, it is needed to set up launch configuration file which is ‘launch.json’.

json: JavaScript Object Notation


Get started with AL
AL is the programming language used for data manipulation whether it is retrieve, insert or modify the records. It can also control the execution of various application objects such as code units, pages etc.

Extensions are programming models where functionality is defined as an addition to the existing objects and defines how they are different or modify the behavior of the solution.

The extension model is object-based; you create new objects, and extend existing objects depending on what you want your extension to do. Table objects define the table schema that holds the data, page objects represent the pages seen in the user interface and code units contain code for logical calculations and for the application behavior. These objects are stored as code, known as AL code, and are saved in files with the .al file extension.

Here it is illustrated how can we build an extension package using AL in Visual studio code (Visual Studio Code combines the simplicity of a source code editor with powerful developer tooling, used for coding and debugging) platform.

Steps that we need to perform:
Download Visual Studio Code.
Download the AL Language extension.
Or we can select it from the file as per below screen
Go to View, click on the extension and install from VSIX 




Select the file from NAV setup 



After Installation, the screen will look like the image below



Then you need to establish the connection with Microsoft Dynamics NAV server and Download the symbol. It comprises of the following steps:

Create a new AL project file, say ALProject1 and save it in the respective directory




Now open the launch.json file and enter the credential 



Now press shift+ctrl+P and Download Symbol


And the respective result will display in the Output section.
Now create a Customer table extension object with one custom field say scheme code (you can make code on validate trigger as well if you want).





Now Press F5 to deploy and run the extension, it will get published to a specific Microsoft Dynamics NAV Server instance. The extension can also be installed for one or more tenants as well.


Business Central Online, the latest offering in the Microsoft Dynamics 365 family has completely changed the way of ‘Customization development’ for any experienced NAV developer. Coding language has changed from C/AL to AL (i.e. AL-Extension V2.0) with the custom code sitting as a separate extension, not at all interfering with the standard code. The custom code now gets deployed as an ‘app’ on top of the standard code base.

Development interface has also undergone a change - earlier development was in C/SIDE, now it is through Visual Studio platform. 

Business Central offers a container-based image environment called ‘Docker’ enabling access to both the AL development environment and the C/SIDE development environment. Docker gets installed on a Windows OS machine – creating the Sandbox environment for a developer to work with. Sandbox is a non-production instance of Business Central available for development and testing.

Characteristic of AL :
  • AL Language (i.e. Extension V2.0) is directly linked with the Visual Studio code environment as an extension – making all Visual studio platform features available for extension development
  • A Package containing all the custom extensions gets created including an app file. The app file is further used for installation or deployment of the custom extensions
  • Development has become flexible with the availability of many new variables (JsonArray, JsonObject etc).
  • The limitations of Table size have been partially removed in AL extension development because the field addition in extension will be part of table extension and not of the base table
  • Various dot net classes as a library is directly available in AL as a datatype – resulting in no need to call it from external sources or with .NET variable references
  • We can invite .NET type members, including methods, properties, and constructors from AL code
  • Availability of Azure Functions -way of running simple pieces of code as a service and can invoke like any other REST ful web services
  • We can maintain your customizations with the security features to allow or disallow to show the codebase
  • If any of your new projects are dependent on any other project i.e. package you can use the dependencies features in the app.json and it will give you all relevant extension file access from the source package

Installing the AL Language Extension in Visual Studio Code

 
Follow these instructions to install an AL extension in Visual Studio Code.
1. Open Visual Studio


Figure 1 – Open Visual Studio

2. Navigate to View-> Extensions




Figure 2 – Navigate to Extensions through the View menu bar

3. Type AL in the search bar and install AL Language



Figure 3 – Search for the AL Language Extension






Figure 4 – Install the AL Language Extension

4. After Installing, Click Reload to complete the AL Extension Installation





Image 5 – Reload the AL Language Extension

























No comments:

Post a Comment

Note: only a member of this blog may post a comment.

Snippet in AL Language Programming

AL Snippets  are pieces of  AL  code that can be reused for faster  coding  in Visual Studio code. They have the prefix “t”, followed by a m...