Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Mastering Microsoft Dynamics 365 Business Central

You're reading from  Mastering Microsoft Dynamics 365 Business Central

Product type Book
Published in Dec 2019
Publisher Packt
ISBN-13 9781789951257
Pages 770 pages
Edition 1st Edition
Languages
Authors (2):
Stefano Demiliani Stefano Demiliani
Profile icon Stefano Demiliani
Duilio Tacconi Duilio Tacconi
Profile icon Duilio Tacconi
View More author details

Table of Contents (25) Chapters

Preface Section 1: Dynamics 365 Business Central - Platform Overview and the Basics of Modern Development
Microsoft Dynamics 365 Business Central Overview Mastering a Modern Development Environment Online and Container-Based Sandboxes Section 2: Developing Extensions for Dynamics 365 Business Central
Extension Development Fundamentals Developing a Customized Solution for Dynamics 365 Business Central Advanced AL Development Report Development with AL Section 3: Debugging, Testing, and Release Management (DevOps)
Installing and Upgrading Extensions Debugging Automated Test Development with AL Source Control Management and DevOps with Business Central Section 4: Advanced Integrations with Dynamics 365 Business Central
Dynamics 365 Business Central APIs Serverless Business Processes with Business Central and Azure Monitoring, Scaling, and CI/CD with Azure Functions Business Central and Integration with the Power Platform Section 5: Moving Solutions to the New Extension Model
Integrating Machine Learning into Dynamics 365 Business Central Moving Existing ISV Solutions to the New Extension Model Useful and Proficient Tools for AL Developers Other Books You May Enjoy

Extension Development Fundamentals

In the previous chapter, we had an overview of the new Modern Development Environment and we learned how to start a new Dynamics 365 Business Central extension project by using the AL Language extension and the Modern Development Environment.

In this chapter, we'll examine the details of the objects of the new extension's development model and how to create new objects with AL, extend standard objects, and handle an AL extension project. More specifically, we'll cover the following topics:

  • The basics of extension development
  • An overview of the main AL objects
  • How to create basic objects in an extension project
  • Best practices for handling your AL project
  • Guidelines for AL objects

By the end of this chapter, you will have learned about the different AL object types, as well as how to create and use them, and (more generally speaking...

Technical requirements

To follow this chapter and in order to experiment with basic object creation in the AL Language, you will need the following:

  • A Microsoft Dynamics 365 Business Central sandbox environment (locally installed on a Docker container or an online one)
  • Visual Studio Code
  • The AL Language extension, which can be installed from the Visual Studio Code marketplace

Basic concepts regarding extensions

As you already know, with Microsoft Dynamics 365 Business Central SaaS, you don't have access to the database or to the standard base code (this is different in the on-premise version, where you can still have access to the base code, and modifying that core is your responsibility). In the SaaS world, you cannot alter the database schema and cannot alter the standard business logic.

In the previous versions of the Microsoft Dynamics ERP, we have always talked about code modification. In the SaaS world, we have to start thinking about a new concept: code extension. To customize Dynamics 365 Business Central, you have to create extensions.

An extension (according to Microsoft's guidelines) is defined as an installable feature built in a way that it does not directly alter source resources and that is distributed as a preconfigured package...

Understanding the basics of the AL Language

An extension of Dynamics 365 Business Central is written using the AL Language. With AL, you can create new objects, extend standard objects, and create custom business logic for your application.

You create an extension for Dynamics 365 Business Central by using Visual Studio Code as your development environment and by using the AL Language extension (as we described in Chapter 2Mastering a Modern Development Environment). When installed, you have full support for developing AL projects.

All Dynamics 365 Business Central functionalities are coded as objects (new objects or extensions of standard objects), and these objects are defined in .al files. A single .al file can define multiple objects (although we don't recommend that).

Extensions are then compiled as .app package files, and this file is the final extension that...

Understanding AL project structure best practices

As we mentioned previously, an AL project is file-based. You have all your .al files inside a project folder. The main problem that you encounter when you start working with a complex project is how to structure the project. How do we organize the objects and the .al files?

There's no written rule for this topic. What we wholeheartedly suggest is to avoid having all the objects (.al files) at the project root level, as shown in the following screenshot:

Here, none of the objects are organized, and if you have a large number of objects, your object list will grow a lot, causing difficulties with handling and retrieving files.

The most sought-after way of structuring your project could be to organize your files by object type, as shown in the following screenshot:

Here, all the extension's code is inside the SRC folder...

Naming guidelines and AL object ranges

When creating extensions for Dynamics 365 Business Central, you need to assign a numerical ID to your objects. The rules for assigning object IDs are as follows:

Range

Purpose

0 – 49,999

Business Central base application. It cannot be used by partners.

5,0000 – 99,999

Per-tenant extensions (resellers who want to customize the delivered solution to the individual needs of a customer).

80,000 – 99,999

Extended objects that you have to modify the permissions of in your development license.

100,000 – 999,999

Reserved for localizing Dynamics 365 Business Central for a specific country or region. It cannot be used by partners.

1,000,000 – 69,999,999

Registered Solution Program (RSP) range.

70,000,000 – 74,999,999

Business Central SaaS apps (AppSource).

 ...

Working on AL coding guidelines

When creating your AL project (and your .al files), remember to always follow these main guidelines.

Inside a .al code file, the structure for all your objects must follow this sequence:

  • Properties
  • Object-specific constructs:
    • Table fields
    • Page layout
    • Actions
  • Global variables:
    • Labels (old text constants)
    • Global variables
  • Methods

Remember to always reference the AL objects by their object name and not by their ID. So, for example, this is how you reference a Record variable or a Page variable:

Vendor: Record Vendor;
Page.RunModal(Page::"Customer Card", ...);

In an event subscriber object, this is how you should reference the publisher object:

[EventSubscriber(ObjectType::Codeunit, Codeunit::MyCodeunit, 'MyIntegrationEvent', '', false, false)]
local procedure MyIntegrationEventSubscriber()
begin
end;

So, let's...

Summary

In this chapter, we looked at the fundamentals of extension development with the AL Language, along with an overview of the main objects for creating applications (tables, pages, codeunits, and so on) and how to create them in Visual Studio Code. Then, we had an overview of the best practices for handling an AL project (project organization, object IDs, naming conventions) and guidelines for writing better code by focusing on the extensibility aspect of our extensions.

We learned how to create objects, how to create an AL project, how to handle its structure, and how to stick to naming conventions with objects.

In the next chapter, we'll implement a real-word extension for Dynamics 365 Business Central by applying all these rules and best practices.

lock icon The rest of the chapter is locked
You have been reading a chapter from
Mastering Microsoft Dynamics 365 Business Central
Published in: Dec 2019 Publisher: Packt ISBN-13: 9781789951257
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}