Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Programming Microsoft Dynamics 365 Business Central
Programming Microsoft Dynamics 365 Business Central

Programming Microsoft Dynamics 365 Business Central: Build powerful, robust, and scalable extensions customized for your business requirements , Seventh Edition

Arrow left icon
Profile Icon Marije Brummel Profile Icon Natalie Karolak Profile Icon Christopher D. Studebaker Profile Icon David Studebaker
Arrow right icon
€33.99
Paperback Oct 2024 466 pages 7th Edition
eBook
€8.99 €26.99
Paperback
€33.99
Subscription
Free Trial
Renews at €18.99p/m
Arrow left icon
Profile Icon Marije Brummel Profile Icon Natalie Karolak Profile Icon Christopher D. Studebaker Profile Icon David Studebaker
Arrow right icon
€33.99
Paperback Oct 2024 466 pages 7th Edition
eBook
€8.99 €26.99
Paperback
€33.99
Subscription
Free Trial
Renews at €18.99p/m
eBook
€8.99 €26.99
Paperback
€33.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Product feature icon AI Assistant (beta) to help accelerate your learning
OR
Modal Close icon
Payment Processing...
tick Completed

Shipping Address

Billing Address

Shipping Methods
Table of content icon View table of contents Preview book icon Preview Book

Programming Microsoft Dynamics 365 Business Central

Introduction to Business Central

“Time changes all things; there is no reason why language should escape this universal law.”

– Ferdinand de Saussure

“Computers are like Old Testament gods; lots of rules and no mercy.”

– Joseph Campbell

Microsoft Dynamics 365 Business Central has one of the largest installed user bases of any enterprise resource planning (ERP) system, serving over two hundred thousand companies and millions of individual users, at the time of writing. The community of supporting organizations, consultants, implementers, and developers continues to grow and prosper. The capabilities of the off-the-shelf product increase with every release. Additionally, the selection of add-on products and services expands both in variety and depth.

The release of Microsoft Dynamics Business Central continues its 30-plus-year history of continuous product improvement. It provides more user options for access and output formatting. For new installations, Business Central includes tools for rapid implementation. For all installations, it provides enhanced business functionality and more support for ERP computing in the cloud, including integration with Microsoft Office 365 and the greater Azure cloud architecture, including Power Platform (Power Automate, Power Apps, Power BI, and Power Virtual Agents).

Our goal in this chapter is to gain a big-picture understanding of Business Central. Upon completing this chapter, you will be able to envision how Business Central can be used by owners and managers of an organization to help manage activities and resources, whether the organization is for-profit or not-for-profit. You will also be introduced to the technical side of Business Central from a developer’s point of view.

In this chapter, we will take a look at Business Central by covering the following topics:

  • A general overview of Business Central
  • A technical overview of Business Central
  • A hands-on introduction to Visual Studio Code (VS Code) development in Business Central

Technical requirements

Developing for Business Central requires access to a Business Central environment, as well as Visual Studio Code installed as the source code editor.

Business Central (hosted by Microsoft in the Azure cloud) can be accessed from a modern browser (Microsoft Edge, Google Chrome, and Mozilla Firefox for Windows or Safari for macOS). Having a subscription to Office 365 is strongly recommended for Word, Excel, and emailing functionality.

Visual Studio Code (VS Code) is a small download (< 200 MB) and has a disk footprint of < 500 MB. It’s lightweight and should easily run on today’s hardware.

For an on-premises installation of VS Code, the following is required:

1.6 GHz or faster processor

  • 1 GB of RAM
  • Windows 10 and 11 (64-bit)
  • macOS (current and previous two versions)
  • Linux (Debian): Ubuntu Desktop 20.04, Debian 10

Linux (Red Hat): Red Hat Enterprise Linux 8, Fedora 36A https://github.com/PacktPublishing/Programming-Microsoft-Dynamics-365-Business-Central-Seventh-Edition.

For a complete list of VS Code requirements, please visit https://code.visualstudio.com/Docs/supporting/requirements.

Installing VS Code will be covered later in this chapter, in the The VS Code integrated development environment section.

Business Central – an ERP system

Business Central is an integrated set of business applications that are designed to service a wide variety of business operations. Microsoft Dynamics 365 Business Central is an ERP system. An ERP system integrates internal and external data across a variety of functional areas, including manufacturing, accounting, supply chain management, customer relationships, service operations, and human resource management, as well as managing other valued resources and activities. By having many related applications well integrated, a fully featured ERP system provides an enter data once, use many ways information processing toolset.

Business Central ERP addresses the following functional areas:

  • Financial Management (for example general ledger, accounts payable, and accounts receivable)
  • Supply Chain Management (for example sales orders, purchase orders, shipping, inventory, and receiving)
  • Relationship management (for example vendors, customers, prospects, employees, and contractors)
  • Manufacturing (for example MRP, sales forecasting, and production forecasting)
  • Other critical business areas (for example human resource management, project management, warehouse management, marketing, cash management, and fixed assets)
  • A complete set of development tools that allow the application to be customized and expanded for specific industries, and even individual businesses.

These are not the only functional areas Business Central addresses, but the main ones. New areas are being added all the time, and many extensions are being produced that address more niche business needs.

A good ERP system, such as Business Central, is modular in design, which simplifies implementation, upgrading, modification, integration with third-party products, and expansion for different types of clients. All the modules in the system share a common database and, where appropriate, common data.

The following groupings of individual Business Central functions are based on the Search menu structure, which is supplemented by information from Microsoft marketing materials. The important thing to understand is the overall components that make up the Business Central ERP system:

Figure 1.1 – Fully integrated functional areas of Business Central

Figure 1.1 – Fully integrated functional areas of Business Central

Business Central has a web browser role-tailored user interface (UI). In Business Central, there’s a universal web-based client that can be used on personal computers, tablets, and other mobile devices.

As illustrated in Figure 1.1, Business Central is a fully integrated system that has multiple functional areas. Let’s take a closer look at them.

Financial management

The foundation of any ERP system is financial management. Irrespective of the business, the money must be kept flowing and tracked. Business Central’s financial management module contains tools that can help you manage the capital resources of a business. These include all or part of the following application functions:

  • General ledger: Managing the overall finances of the firm
  • Cash management and banking: Managing the inventory of financial assets
  • Accounts receivable: Tracking the incoming revenue
  • Accounts payable: Tracking outgoing funds
  • Analytical accounting: Analyzing the various flows of funds
  • Inventory and fixed assets: Managing inventories of goods and equipment
  • Multicurrency and multilingual: For supporting international business activities

Business Central is not just a financial system – it is the basis for all other functional areas. The main areas related to inventory consist of making goods, moving goods, and servicing goods. Other areas that don’t focus on inventory are project management, managing employees, customer communications, and internal reporting.

Manufacturing

Business Central manufacturing is general-purpose enough to be appropriate for Make to Stock (MTS), Make to Order (MTO), and Assemble to Order (ATO), as well as various subsets and combinations of those. Although Business Central is not particularly suitable for most process manufacturing and some of the very high-volume assembly line operations off the shelf, there are third-party extension enhancements available for those applications. As with most of the Business Central application functions, manufacturing can be implemented either in a basic mode or as a fully featured system. Business Central manufacturing includes the following functions:

  • Product design (Bills of Materials [BOMs] and routings) for the structure management of product components and the flow management of manufacturing processes
  • Capacity and supply requirement planning, for tracking the intangible and tangible manufacturing resources
  • Production scheduling (infinite and finite), execution, and tracking quantities and costs, plus tracking manufacturing resources’ planned use, both on a constrained and unconstrained basis

Supply chain management

Some of the functions that are categorized as part of Business Central’s supply chain management (SCM), such as sales and purchasing, are actively used in almost every Business Central implementation. The supply chain applications in Business Central include all or parts of the following applications:

  • Sales order processing and pricing: To support the heart of every business
  • Purchasing (including requisitions): For planning, entering, pricing, and processing purchase orders
  • Inventory management: For managing inventories of goods and materials
  • Warehouse management including receiving and shipping: For managing the receipt, storage, retrieval, and shipment of material and goods in warehouses

As a whole, these functions constitute the base components of a system that’s appropriate for distribution operations, including those that operate on an ATO basis.

Business intelligence and reporting

Although Microsoft marketing materials identify business intelligence (BI) and reporting as though they’re separate modules within Business Central, it’s difficult to physically identify them as such. Most of the components that are used for BI and reporting purposes are (appropriately) scattered throughout various application areas. In the words of one Microsoft document, business intelligence is a strategy, not a product. The following functions within Business Central support a BI strategy:

  • Standard reports: Distributed and ready to use by end users
  • Financial reporting and analysis reports: A specialized report writer for general ledger data
  • Queries, XMLports, and reports: The AL programming language supports the creation of a wide variety of report formats [SQL Server Reporting Services (SSRS), Microsoft Word, and Excel], queries, XML, and CSV files
  • Analysis by dimensions: A capability embedded in many Business Central tools
  • Office 365 Interfaces: Including communicating Excel data either into or out of Business Central
  • RDLC report viewer: Allows you to present Business Central data in a variety of textual and graphic formats, including providing user interactive capabilities
  • Interface capabilities such as SOAP, ODATA, and REST web services: Technologies to support interfaces between Business Central and external software products
  • Standard packages for Power BI: Integrated in the role center as well as dashboards

Relationship management

Business Central’s relationship management (RM) functionality is the little sibling of the fully featured standalone Microsoft CRM system and Dynamics 365 for Sales and Dynamics 365 for Marketing. The big advantage of Business Central RM is its tight integration with Business Central customer and sales data.

Also falling under the heading of the customer relationship module is the Business Central service management (SM) functionality. The following functionalities fall under RM and SM:

  • Relationship management:
    • Marketing campaigns, to plan and manage promotions
    • Customer activity tracking, to analyze customer orders
    • To-do lists, to manage what is to be done and track what has been done
  • Service management:
    • Service contracts, to support service operations
    • Warranty tracking for items and repair
    • Labor and part consumption tracking, to track resources that are consumed by the service business
    • Planning and dispatching, to manage service calls

Human resource management

The Business Central human resources module is very small, but it relates to a critical component of the business: employees. Basic employee data can be stored and reported via the master table (in fact, you can use the human resources (HR) module to manage data about individual contractors in addition to employees). A wide variety of individual employee attributes can be tracked through the use of tailorable dimension fields:

  • Employee tracking: Maintain basic employee description data
  • Skills inventory: Inventory of the capabilities of employees
  • Absence tracking: Maintain basic attendance information
  • Employee statistics: For tracking government and other required employee attribute data, such as age, gender, and length of service

Project management

The Business Central project management module consists of allocating, budgeting, and utilizing resources for projects that can be either short-term or long-term. They can be external (in other words, billable) or internal. This module is often used by third parties as the base for vertical market add-ons (such as construction or job-oriented manufacturing). This application area includes parts or all of the following functions:

  • Budgeting and cost tracking, for managing project finances
  • Scheduling, for planning project activities
  • Resource requirements and usage tracking, for managing people and equipment
  • Project accounting, for tracking the results

Now that we’ve learned about Business Central at a functional level, let’s switch to a developer’s perspective.

A developer’s overview of Business Central

From the point of view of a developer, Business Central consists of a set of applications with thousands of potentially extensible, off-the-shelf program objects written in the AL programming language. Visual Studio Code, as the integrated development environment (IDE), in combination with the AL Language extension, allows us to work with existing objects and create new ones. Our AL code will compile into a *.app file as yet another application to publish and install.

Note

This book provides an overview of Business Central, including the basics, so that you have a quick hands-on start. To find the complete developer documentation, please refer to Microsoft Docs at https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/#resources-for-a-developer.

Business Central applications

As a developer, we need to be aware of the following applications that form the Business Central application. They have been listed in their dependency hierarchy from top to bottom:

  • Base Application: This provides core business processes such as sales and purchasing, customer and vendor management, plus complex processes, such as assembly, manufacturing, service, and directed warehouse management – simply put, the business logic.
  • Business Foundation (since version 24): This serves as a foundation for developing business applications, such as No. series management or dimension management. The standard functionality is used globally and not tied to a specific area. Before version 24, the content resided in the Base Application.
  • System Application: This contains objects to serve mere technical purposes, such as emailing, OAuth, and RegEx, and provides mathematical functions. These objects support the base application and its interaction with the platform and Microsoft ecosystem.
  • System: This provides system objects and virtual tables. We will discuss some of these objects at the end of Chapter 2.

Tip

The Business Central source code is being developed at https://github.com/microsoft/BCApps. The repository is a contribution project. At the time of writing this book, the repository consisted of the System Application, the Business Foundation, and various tools. The Base Application will be added in the future. Please refer to the repository’s README file for more current information.

Business Central object types

Let’s start with basic definitions of the Business Central object types that will be covered in this book. This is meant to act as a rough overview – we will cover them later in this chapter again:

  • Table: Tables serve both to define the data structure and to contain the data records.
  • Table extension: Table extensions allow for the creation of companion tables that are linked to tables defined by Microsoft in the base product or by other solutions.
  • Page: Pages are the way data is formatted and displayed appropriately for each of the client types and user roles.
  • Page extension: Page extensions allow controls in existing pages to be added or hidden.
  • Report: Reports are provided to display data to the user in hard copy format, computer file format (PDF, Microsoft Word, or Excel), on-screen (preview mode), or via a printing device. Report objects can also update data in processes with or without data display.
  • Report Extension: Report extensions allow you to add columns to existing reports’ datasets, add new data items, extend trigger logic, provide additional fields and logic to request pages, and define new layouts.
  • Codeunit: Codeunits are containers for code that are utilized by other objects. Codeunits are always structured in code segments called procedures.
  • Query: Queries support extracting data from one or more tables, making calculations, and outputting them in the form of a new data structure. Queries can output data directly into charts, Excel, XML, and OData. They can be used as an indirect source for pages and reports.
  • XMLport: XMLports allow you to import and export data to/from external files. The external file structure can be in XML or other file formats.
  • Profile: Profiles allow you to define Role Centers and group page customizations.
  • Enum: Enums (enumerated lists) are extendable options that can be connected to tables and interfaces.
  • Enum extension: Enum extensions are extra options that are added to Enums from either the Microsoft Business Central Base App or other extensions.

The Visual Studio Code integrated development environment

Business Central includes an extensive set of software development tools. These Business Central development tools can be accessed through Visual Studio Code and the AL Language extension. We will install the extension soon in the Extensions section, and we will learn about the AL Language extension in the AL programming language section.

The Visual Studio Code IDE is Microsoft’s most popular free code editor and is available for Windows, Linux, and macOS. The images used in this book have been taken on a Windows system. You can download Visual Studio Code from https://code.visualstudio.com/:

Figure 1.2 – Visual Studio (VS) Code with the AL Language extension installed

Figure 1.2 – Visual Studio (VS) Code with the AL Language extension installed

Let’s explore its interface in more detail.

Visual Studio Code icons

When we open Visual Studio Code, we will see five icons. These icons appear on the left-hand side of the screen. They also determine the navigation part that appears on the left-hand side of your screen. If you click on an icon twice, the navigation part will be hidden and allow full-screen code editing. Let’s see what each of these do in detail.

EXPLORER

The EXPLORER view is the default view when you open a project. It allows you to view the files in a project and select one or more files for editing. The EXPLORER view is shown in the following screenshot:

Figure 1.3 – EXPLORER in VS Code

Figure 1.3 – EXPLORER in VS Code

While the list of files is fine for smaller projects, sometimes, it is necessary to locate a file in a larger list or even text within files.

Tip

We can use Ctrl + P to search files by name.

SOURCE CONTROL

VS Code provides access to a built-in connection to SOURCE CONTROL. When source control is activated, all changes that are made to files are automatically tracked and displayed in this window:

Figure 1.4 – SOURCE CONTROL in VS Code

Figure 1.4 – SOURCE CONTROL in VS Code

Further reference

The video Using Git with Visual Studio Code (https://youtu.be/i_23KUAEtUM) explains how to get started with SOURCE CONTROL in Visual Studio Code.

Debugger

You can use the built-in debugger to do basic troubleshooting for your code. The RUN AND DEBUG view is shown in the following screenshot:

Figure 1.5 – The debugger in VS Code

Figure 1.5 – The debugger in VS Code

We will learn more about debugging in Business Central in Chapter 7, Intermediate AL.

Extensions

Out of the box, Visual Studio Code doesn’t understand the Business Central AL Language syntax. To activate the compiler, an extension needs to be installed in the EXTENSIONS window.

This extension, called AL Language extension for Microsoft Dynamics 365 Business Central (in this book, it will be referred to as AL Language extension), can be downloaded from the Visual Studio Marketplace or installed directly from Visual Studio Code using Search Extensions in Marketplace:

Figure 1.6 – The AL Language extension in VS Code

Figure 1.6 – The AL Language extension in VS Code

Note

The Visual Studio Code Marketplace can be found at https://marketplace.visualstudio.com/.

Microsoft does a monthly update of Business Central and the AL Language extension. Usually, you install and use the most current version released in the Marketplace. There is also a pre-release version available that allows early access to features that are being prepared for the next major version of Business Central.

SEARCH

The SEARCH view provides an advanced search and replace option within the files of your project. The SEARCH view is shown in the following screenshot:

Figure 1.7 – SEARCH in VS Code

Figure 1.7 – SEARCH in VS Code

Visual Studio Code provides an easy-to-understand toolset that’s used by many programmers. The AL compiler extension provides an entry point for you to extend and develop new areas in the Microsoft 365 Business Central application. Later, we will get into the additional benefits of its deep integration with Git and repositories to control code development between one and more developers.

AL programming language

The language in which Business Central is coded is AL. A small sample of AL code within Visual Studio Code is shown here:

Figure 1.8 – Example of AL code

Figure 1.8 – Example of AL code

AL syntax is similar to Pascal syntax. But other than Pascal, AL is not an object-oriented programming language but an object-based one. Code readability is always enhanced by careful programmer attention to structure and logical variable naming, as well as ensuring that the process flow is consistent with that of the code in the base product and that there is good documentation both inside and outside of the code.

Good software development focuses on design before coding and accomplishing design goals with a minimal amount of code. Dynamics Business Central facilitates that approach. In 2012, a team made up of Microsoft and Business Central community members began the NAV design patterns project. As defined by Wikipedia, a design pattern is a general reusable solution to a commonly occurring problem.

In 2022, long after the transition to Business Central and the AL language, the project was relaunched as Business Central design patterns and moved to another website: https://alguidelines.dev/docs/.

Note

One of the primary goals of this project is to document patterns that exist within Business Central. In addition, new best practice patterns have been suggested as ways to solve common issues we encounter during our customization efforts. Now, when we work on Business Central enhancements, we will be aided by references to the documentation of patterns within Business Central. This allows us to spend more of our time designing a good solution using existing, proven procedures (the documented patterns) and less time writing and debugging code. Please refer to the Reusing Code section of Business Central at https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/devenv-programming-in-al#reusing-code for more information.

Much of our Business Central development work is done by assembling references to previously defined objects and procedures and adding new data structures where necessary. As the tools for Business Central design and development that are provided both by Microsoft and the Business Central community continue to mature, our development work becomes more oriented toward design and less toward coding. The result is that we are more productive and cost-effective on behalf of our customers. Everyone wins.

Business Central object elements

Here are some important terms that are used in Business Central:

  • Field: An individual data item, defined either in a table or in the working storage (temporary storage) of an object.
  • Record: A group of fields (data items) that are handled as a unit in many operations. Table data consists of rows (records) with columns (fields).
  • Control: In Microsoft Developer Network (MSDN), a control is defined as a component that provides (or enables) UI capabilities.
  • Properties: These are the attributes of the element, such as an object, field, record, or control, that define some aspect of its behavior or use. Example property attributes include display captions, relationships, size, position, and whether the element is editable or viewable.
  • Trigger: These are mechanisms that initiate (fire) an action when an event occurs and is communicated to the application object. A trigger in an object is either empty or contains code that is executed when the associated event fires the trigger. Each object type, data field, control, and so on may have its own set of predefined triggers. The event trigger name begins with On – for example, OnInsertRecord, OnOpenPage, or OnNextRecord. Business Central triggers have similarities to those in SQL, but they are not the same (similarly named triggers may not even serve similar purposes). Business Central triggers are locations within objects where a developer can place comments or AL code.
  • Procedures: These can be defined by the developer. They are callable routines that can be accessed by other AL code from either inside or outside the object where the called procedure resides. Many procedures are provided as part of the standard product. As developers, we may add custom procedures as needed.
  • Attributes: An attribute is a modifier on a procedure declaration that controls the procedure’s use and behavior.
  • Object numbers and field numbers: All objects of the same object type are assigned a number that’s unique within the object type. All fields within a table object are assigned a number that’s unique within the object (that is, the same field number may be repeated within many objects, regardless of whether it is referring to similar or different data). In this book, we will generally use comma notation for these numbers (fifty thousand is 50,000). In AL, no punctuation is used. The object numbers range from 1 (one) to 49,999 and those from 100,000 to 999,999 are reserved for use by Business Central as part of the base product. Numbers from 1,000,000 (one million) to 74,999,999 are reserved for partners. Field numbers in standard objects often start with one (1). Historically, object and field numbers from 50,000 to 99,999 are generally available to the rest of us for assignment as part of extensions that are developed. Field numbers from 90,000 to 99,999 should not be used for new fields that have been added to standard tables as those numbers are sometimes used in training materials. Microsoft allocates ranges of object and field numbers to independent software vendor (ISV) developers for their add-on enhancements. Some such objects (the 14 million range in North America, and other ranges for other geographic regions) can be accessed, modified, or deleted, but they can’t be created using a normal development license. Others (such as in the 37 million range) can be executed but not viewed or modified with a typical development license. The following table summarizes this object numbering practice:

Object Number Range

Usage

1 – 9,999

Base application objects

10,000 – 49,999

Country-specific objects

50,000 – 99,999

Customer-specific objects

100,000 – 999,999

Localization-specific objects

1,000,000 – 74,999,999

Partner-created objects

Table 1.1 – BC object number ranges

  • Events: Procedures can subscribe to events that are raised in the system. Business Central has both platform and manual events. Procedures can also be used to raise events.
  • Work date: This is a date that’s controlled by the user operator. It is used as the default date for many transaction entries. The system date is the date that’s recognized by Windows. The work date that can be adjusted at any time by the user is specific to the workstation and can be set to any point in the future or the past. This is very convenient for procedures such as the ending sales order entry for one calendar day at the end of the first shift, and then the second shift entering sales orders dated to the next calendar day. Some settings allow you to limit the range of work dates allowed. The work date can be set by clicking on the cogwheel drop-down list next to the question mark icon and selecting the My Settings option:
Figure 1.9 – Settings in the Business Central client

Figure 1.9 – Settings in the Business Central client

Clicking on My Settings in the dropdown displays the My Settings screen. Here, we can enter a new Work Date value:

Figure 1.10 – Work Date on the My Settings screen

Figure 1.10 – Work Date on the My Settings screen

In addition to basic functionality, you will also encounter terminology that’s used in the functional areas that are important to understand for development purposes.

Business Central functional terminology

For various application functions, Business Central uses terminology that’s more similar to accounting than to traditional data processing terminology. Here are some examples:

  • Journal: A table of unposted transaction entries, each of which represents an event, an entity, or an action to be processed. There are general journals for general accounting entries, item journals for inventory changes, and so on.
  • Ledger: A detailed history of posted transaction entries that have been processed – for example, the general ledger, customer ledger, vendor ledger, and item ledger. Some ledgers have subordinate detail ledgers, typically providing a greater level of quantity and/or value detail. With minor exceptions, ledger entries cannot be edited. This maintains auditable data integrity. Business Central has a posting logic-driven data integrity that is founded on General Ledger Entries tying to all other ledgers.
  • Posting: The process by which entries in a journal are validated, and then entered into one or more ledgers.
  • Batch: A group of one or more journal entries, posted at the same time.
  • Register: An audit trail showing a history, by entry number ranges, of posted journal batches.
  • Document: A formatted page such as an invoice, a purchase order, or a payment check, typically one page for each primary transaction (a page may require display scrolling to be fully viewed).

UI

The Business Central UI is designed to be role-oriented (also called role-tailored). The term role-oriented means tailoring the available options to fit the user-specific job tasks and responsibilities.

The first page that a user will see is the Role Center page. The Role Center page provides the user with a view of work tasks to be done; it acts as the user’s home page. The Role Center home page should be tailored to the job duties of each user so there are a variety of Role Center page formats for any installation.

Someone whose role focuses on order entry will probably see a different Role Center home page than the user whose role focuses on invoicing, even though both user roles are in what we generally think of as sales and receivables. The Business Central tailorable Role Center allows a great deal of flexibility for implementers, system administrators, managers, and individual users to configure and reconfigure screen layouts and the set of functions that are visible to a particular user.

The following screenshot is the out-of-the-box Role Center for a business manager:

Figure 1.11 – Business Central – Role Center

Figure 1.11 – Business Central – Role Center

The key to properly designing and implementing any system, especially a role-tailored system, is the quality of the user profile analysis that’s done as the first step in requirements analysis. User profiles identify the day-to-day needs of each user’s responsibilities, relative to accomplishing the business’s goals. Each user’s tasks must be mapped to individual Business Central functions or elements, identifying how those tasks will be supported by the system.

Important

A successful implementation requires the use of a proven methodology. The upfront work must be done and done well. The best programming cannot compensate for badly defined goals.

In our exercises, we will assume that the upfront work has been well done, so we will concentrate on addressing the requirements that have been defined by our project team.

Hands-on development in Business Central

One of the best ways to learn a new set of tools, such as those that make up a programming language and environment, is to experiment with them. We’re going to have some fun doing that throughout this book. To do so, we’re going to experiment where the cost of errors (otherwise known as learning) is small. Our development work will consist of a custom Business Central application that will be relatively simple but realistic.

We’re going to do our work using the Cronus demo database that is available with all Business Central distributions and is installed by default when we install the Business Central demo system. The simplest way is to use the sandbox.

Note

You can find up-to-date information on getting started with Business Central sandboxes via Microsoft Docs at https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/devenv-sandbox-overview.

The Cronus database contains all of the Business Central objects and a small, but reasonably complete, set of data populated in most of the system’s functional application areas. Our exercises will interface very slightly with the Cronus data, but they will not depend on any specific data values already there.

Business Central development exercise scenario

Our business is a small radio station that features a variety of programming, news, music, listener call-ins, and other program types. Our station call letters are WDTU. Our broadcast materials come from several sources and in several formats: vinyl records, CDs, MP3s, and downloaded digital (usually MP3s). While our station has a large library, especially of recorded music, sometimes, our program hosts (also called disc jockeys or DJs) want to share material from other sources. For that reason, we need to be able to easily add items to our playlists (the list of what is to be broadcast) and also have an easy-to-access method for our DJs to preview MP3 material.

Like any business, we have accounting and activity tracking requirements. Our income is from selling advertisements. We must pay royalties for music played, fees for purchased materials, such as prepared text for news, sports, and weather information, and service charges for our streaming internet broadcast service. As part of our licensed access to the public airwaves, a radio station is required to broadcast public service programming at no charge. Often, this is in the form of public service announcements (PSAs), such as encouraging traffic safety or reduction in tobacco use.

Like all radio stations, we must plan what is to be broadcast (create schedules) and track what has been broadcast (such as advertisements, music, purchased programming, and PSAs) by date and time. We bill our customers for this advertising, pay our vendors their fees and royalties, and report our public service data to the appropriate government agency.

Getting started with application design

The design for our radio station will start with a Radio Show table, a Radio Show Card page, a Radio Show List page, and a simple Radio Show List report. Along the way, we will review the basics of each Business Central object type.

When we open Visual Studio, we need to create a new project folder. This can be done using the Command Palette via View | Command Palette... or F1 or Ctrl + Shift + P. Then, type AL:Go!:

Figure 1.12 – Command Palette in VS Code

Figure 1.12 – Command Palette in VS Code

The project folder will default to your Documents folder if you run this on a Windows machine. We will call our project WDTU:

Figure 1.13 – Naming the project folder

Figure 1.13 – Naming the project folder

Select the version with which you are working (the public cloud will always be the latest version; your on-premises version may be a different version):

Figure 1.14 – Platform and corresponding BC major release

Figure 1.14 – Platform and corresponding BC major release

In the bottom right corner of VS Code, a notification about missing symbols will appear. Clicking on the Download symbols button, we now need to choose a server type to download the symbols from. Both provided options (own server or Microsoft-hosed SaaS, such as a sandbox) will create a launch.json file that we will deal with soon. But first, we must close the Could not download symbols error message that appeared together with the server selection prompt.

Now, let’s inspect the folder structure that has been created.

Folder structure

A folder called WDTU has been created with some default files and subfolders. The HelloWorld.al file can be deleted immediately. This file is a page extension that will be explored more fully in Chapter 4, Pages – The Interactive Interface:

Figure 1.15 – Folder structure after AL: Go

Figure 1.15 – Folder structure after AL: Go

Let’s dive a bit deeper into the folder structure.

Note

The json files that will be explained in the upcoming sections consist of more settings than this book is going to cover. We will only look at the mandatory or most used settings for now.

All settings are explained at Microsoft Docs (https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/devenv-json-files).

launch.json

Inside a subfolder called .vscode, a file is created called launch.json that defines the connection to all our Business Central target environments. Each connection is defined in a separate configuration object. We will soon use a configuration for downloading symbols, publishing our application, and debugging.

Let’s take a moment to update the configuration that was recently created for us. The following settings apply to all configurations:

  • name: For documentation purposes only. You can put the name of your project here. If more than one configuration is defined, VS Code uses the names to build a lookup list.
  • environmentType: This specifies which environment to use to connect to Business Central. It must be set to Sandbox or Production in the cloud, and to OnPrem for on-premises. This field is mandatory.
  • startupObjectId: This setting determines which object is executed when the project is published. Specifying any startup settings is optional.
  • startupObjectType: This setting works alongside startupObjectId and specifies whether the object to open after publishing is a table, page, report, or query object. The default is Page.
  • startupCompany: This specifies the name of the company to open after publishing. If specified, the startupObjectId and startupObjectType settings must also be defined.

For addressing cloud environments (production or sandbox), we will need to populate one additional setting:

  • environmentName: This specifies which named environment to use in cases where multiple sandboxes are owned by the same tenant

The following settings are required for connecting to your own servers:

  • server: This contains a URL to the development endpoint of your server.
  • port: This optional setting specifies the port that’s assigned to the development service. This is for on-premises installations only and is required if the default port is not used for the server instance you are connecting to.
  • serverInstance: A server can have multiple instances.
  • authentication: This can be UserPassword, AAD, or Windows. The default is UserPassword.

app.json

Located in the main folder, the app.json file contains properties about your extension, such as its name and version. These are mandatory fields; the others that are available are optional:

  • id: This is a unique ID (GUID) for your extension and is autogenerated. Never change this value.
  • name: The name of your extension as it will be displayed to the user.
  • publisher: This usually contains the name of the company or individual who owns the intellectual property of the extension. It will be displayed to the user.
  • version: Your extensions can be versioned using this property. You can use this when you create a new version of the extension to determine if upgrade code needs to be executed.
  • idRange: This tells the compiler which object numbers are to be used for this extension. You must provide a range for application object IDs in "idRanges": [{"from": 50100,"to": 50200},{"from": 50202,"to": 50300}] format.
  • platform, application, and runtime: These properties were automatically set when we ran AL: Go!. They determine the minimum version of Business Central (platform, application) and the minimum AL Language features (runtime) our application shall be compatible with.

Symbol files

Before we can start creating our extension, we need to do one more thing: download the symbol files. The compiler needs the symbol files to determine whether the dependencies are correct. The symbol files contain metadata about other extensions. To download the required Business Central applications from our development environment, we need to select AL: Download symbols from the Visual Studio Command Palette:

Figure 1.16 – The AL: Download symbols command

Figure 1.16 – The AL: Download symbols command

Note

When the symbol files are downloaded, by default, they’ll be placed in the ./alpackages folder of your project.

Later, in Chapter 2, in the Non-Extensible Tables section, and Chapter 3, in the Data Structure Examples section, we will use the AL Explorer in VS Code to inspect the symbol files.

Application tables

Table objects are the foundation of every Business Central application. Tables contain data structure definitions, as well as properties that describe the behavior of the data, including data validations and constraints.

More business logic is required in complex applications than in simple data type validation, and Business Central allows AL code to be put in the table to control the insertion, modification, and deletion of records, as well as logic at the field level.

Note

When the bulk of the business logic is coded at the table level, it is easier to develop, debug, support, modify, and even upgrade. Good design in Business Central requires that as much of the business logic as possible resides in the tables.

Having the business logic coded at the table level doesn’t necessarily mean that the code resides in the table. The Business Central online documentation recommends the following guidelines for placing AL code:

  • In general, put the code in codeunits instead of on the object on which it operates. This promotes a clean design and provides the ability to reuse code. It also helps enforce security. For example, typically, users do not have direct access to tables that contain sensitive data, such as the general ledger entry table, nor do they have permission to modify objects. If you put the code that operates on the general ledger in a codeunit object, give the codeunit object access to the table, and give the user permission to execute the codeunit object, then you will not compromise the security of the table and the user will be able to access the table.
  • Outside codeunit objects, put the code as close as possible to the object on which it operates. For example, you should put code that modifies records in the triggers of the table fields.

Designing a simple table

Our primary master data table will be the Radio Show table. This table lists our inventory of shows that are available to be scheduled.

Each master table has a standard field for the primary key (a Code data type field of 20 characters called No.) and has standard information regarding the entity the master record represents (for example, Name, Address, and City for the Customer table, and Description, Base Unit of Measure, and Unit Cost for the Item table).

The Radio Show table will have the following field definitions (we may add more later on):

Field Names

Definitions

No.

20-character text (code)

Radio Show Type

10-character text (code)

Name

100-character text

Run Time

Duration

Host No.

20-character text (code)

Host Name

100-character text

Average Listeners

Decimal

Audience Share

Decimal

Advertising Revenue

Decimal

Royalty Cost

Decimal

Table 1.2 – The Radio Show table’s field names and data types

In the preceding list, three of the fields are defined as Code fields, which are text fields that limit the alphanumeric characters to uppercase values. Such Code fields are used throughout Business Central for primary key values. They are used to reference or be referenced by other tables (foreign keys). No. will be the unique identifier in our table. We will utilize a set of standard internal Business Central procedures to assign a user-defined No. series range that will auto-increment the value on table insertion and possibly allow for user entry (so long as it is unique in the table) based on a setup value. Note that Host No. references the standard Resource table, while the Radio Show Type field will reference a custom table that we will create to allow for flexible Type values.

We must design and define the reference properties at the field level, as well as compile them before the validation will work. At this point, let’s just get started with these field definitions and create the foundation for the Radio Show table.

Creating a simple table

The easiest way to create a table is by using snippets. Snippets are textual templates for a specific programming task, such as for creating a new table object. To use snippets, Visual Studio Code needs to understand that our file is written in the AL language. This can be done by saving the file with the .al extension.

To add a new AL file, right-click on the space below the app.json file and select New File... from the context menu. Name it RadioShow.table.al and press Enter:

Figure 1.17 – Adding the Radio Show table

Figure 1.17 – Adding the Radio Show table

Note

As a best practice exemplified by Microsoft, always extend your AL filenames with the <object name>.<object type>.al pattern. You can change the <object name> part at any time later. Try to avoid spaces in filenames. Although using camel case is generally recommended, this book will continue using lowercase object types.

Now, we can use the snippet called ttable. If we type in the letters tt, IntelliSense will suggest this snippet:

Figure 1.18 – Snippets in VS Code

Figure 1.18 – Snippets in VS Code

Code snippets are templates in Visual Studio Code that are available in IntelliSense. Snippets make it easier to enter repeating code patterns and we can use them for object definition templates. This snippet creates content for our file and sets the cursor on the place where we need to define the object ID:

Figure 1.19 – A snippet of the generated code structure

Figure 1.19 – A snippet of the generated code structure

We will press Backspace, then Ctrl + spacebar, and finally Enter to select value 50100. Next, we must press the Tab key to go to the next field, which contains the object name, where we will type "Radio Show". The snippet has already created a field with the default ID of 1. The field name is MyField and its type is Integer. We will change the name to "No." and the type to Code[20].

The next field will be field number 2. Just like for the object ID we just created, you can use Ctrl + spacebar to let the AL language suggest a free ID. You can also place a new field, 3, between field numbers 1 and 2, or resort (not renumber) the fields at any time later.

Alternatively, you can number the field IDs manually, leaving smaller gaps between each field and larger gaps between sets of fields with a particular purpose.

Note

Once a table is referenced by other objects or contains any data, the field numbers of the previously defined fields should not be changed.

The following screenshot shows our new table definition in the .al file:

Figure 1.20 – Radio Show table AL code

Figure 1.20 – Radio Show table AL code

Note

You can remove anything that’s automatically supplied that you don’t need from this snippet. Here, we’ve removed the DataClassification and keys sections, variable declarations, and triggers. We will cover their usage and details in Chapter 2, Tables.

Pages

Pages provide views of data or processes that are designed for on-screen display (or exposure as web services and REST APIs) and also allow user data entry into the system. Pages act as containers for action items (menu options).

From a user perspective, there are several basic types of display/entry pages available in Business Central by default:

  • List
  • Card
  • Document
  • Journal/worksheet

We will review each page type here.

There are also page parts (they look and program like a page but aren’t intended to stand alone), dialogs, as well as user interfaces (UIs) that display like pages, but are not page objects. The latter UIs are generated by various dialog methods. In addition, there are special page types, such as Role Center pages and wizards. All those will be covered later in Chapter 4, Pages – The Interactive Interface.

Standard elements of pages

A page consists of page properties and triggers, controls, and control properties. Data controls are generally either labels displaying constant text or graphics, or containers that display data or other controls. Controls can also be buttons, action items, and page parts. While there are a few instances where we must include AL code within page or page control triggers, it is good practice to minimize the amount of code that’s embedded within pages. Any data-related AL code should be located in the table object rather than in the page object.

List pages

List pages display a simple list of any number of records in a single table. The Customers list page (with its associated FactBoxes) in the following screenshot shows a subset of the data for each customer displayed. List pages often do not allow you to enter or edit data:

Figure 1.21 – The Customers list page

Figure 1.21 – The Customers list page

Card pages

Card pages display one record at a time. They are generally used for entering or displaying individual table records. Examples of frequently accessed card pages include Customer Card for customer data, Item Card for inventory items, and G/L Account Card for general ledger accounts.

Card pages have FastTabs (a FastTab consists of a group of controls, with each tab focusing on a different set of related customer data). FastTabs can be expanded or collapsed dynamically, allowing the data that’s visible to be controlled by the user at any time. Important data elements can be promoted to be visible all the time, even when a FastTab is collapsed.

Card pages for master records display all the required data entry fields. If a field is set to ShowMandatory (a control property that we will discuss in Chapter 4, Pages – The Interactive Interface), a red asterisk will appear until the field is filled. Typically, card pages also display FactBoxes, which contain summary data about related activity. Thus, cards can be used as the primary inquiry point for master records. The following screenshot shows an example standard Customer Card:

Figure 1.22 – The Customer Card page

Figure 1.22 – The Customer Card page

Document pages

A document page looks like a card page with one tab containing a list part page. An example of a document page is the Sales Order page shown in the following screenshot. In this example, the first tab (General) and the last four (invisible) tabs are in card page format and show order data fields that have a single occurrence on the page (in other words, they do not occur in a repeating column).

The second tab from the top (Lines) is in a list part page format (all fields are in repeating columns) that shows the order line items. Sales Order line items may include products to be shipped, special charges, comments, and other pertinent order details.

The information to the right of the data entry area is related to data and computations (FactBoxes) that have been retrieved and formatted. The top FactBox (Sell-to Customer Sales History) counts and links various sales documents for the current customer:

Figure 1.23 – The Sales Order document page

Figure 1.23 – The Sales Order document page

After the short introduction into pages, let's resume designing our WDTU application.

Journal/worksheet pages

Journal and worksheet pages look very much like list pages. They display a list of records in the body of the page. Many also have a section at the bottom that shows details about the selected line and/or totals for the displayed data. These pages may include a filter pane and perhaps a FactBox. The biggest difference between journal/worksheet pages and basic list pages is that journal and worksheet pages are designed to be used for data entry (though this may be a matter of personal or site preference).

An example of the Payment Journals page in finance is shown in the following screenshot:

Figure 1.24 – The Payment Journals page

Figure 1.24 – The Payment Journals page

After the short introduction into pages, let's resume designing our WDTU application.

Creating a list page

Now, we will create a list page for the table we created earlier. A list page is the initial page that’s displayed when a user initially accesses any data table for the first time. Since the AL language doesn’t have wizards, we’ll use snippets to create the framework for objects and procedures. Visual Studio Code allows you to create custom snippets if you have repeated patterns that are not available out of the box.

Our first list page will be the basis for viewing our Radio Show master records. From Visual Studio Code, add a new file and enter the name RadioShowList.page.al. Now, we can use the tpage snippet (choose the Page of type List entry):

Figure 1.25 – A snippet page being used to generate a page template

Figure 1.25 – A snippet page being used to generate a page template

Now, we will set the ID to 50100 and the name to "Radio Show List", as well as change SourceTable to "Radio Show", as shown in the following screenshot:

Figure 1.26 – Fill in the information as shown

Figure 1.26 – Fill in the information as shown

After doing this, we can see that NameSource is highlighted as a problem, and the PROBLEMS window at the bottom of our screen tells us that NameSource does not exist in this context.

The reason why this problem is occurring is because of the combination of the table object and this page. We joined these objects by selecting the Radio Show table as SourceTable for this page. By joining them, the page object now has a dependency on the table object.

The next step will be to add the fields from the table to the page in the repeater. We will remove the NameSource field to do so.

Page fields are declared as field(Name; Expression) { }. The Name value can be freely chosen and can be called by other extensions later. IntelliSense helps us fill in the Expression value for a SourceTable field: By adding Rec. to the front, the compiler will identify it as a field from the current record.

After that, we can replace the snippet’s GroupName with Group.

We should also remove everything we don’t need, such as FactBoxes and actions:

Figure 1.27 – The completed Radio Show list page so far

Figure 1.27 – The completed Radio Show list page so far

We can view the page by modifying the launch.json file. Change startupObjectId to 50100 and select AL: Publish without debugging from the Command Palette, as shown in the following screenshot:

Figure 1.28 – Setting startupObjectId to the Radio Show list page’s object number

Figure 1.28 – Setting startupObjectId to the Radio Show list page’s object number

This will launch the Business Central application with our newly created page as the startup object:

Figure 1.29 – The Radio Show list page in the Business Central client. Text readability is not a requirement here; the intent is to show the empty Radio Show list

Figure 1.29 – The Radio Show list page in the Business Central client. Text readability is not a requirement here; the intent is to show the empty Radio Show list

Because our table doesn’t contain any data, we will only see a header that displays the name of our page.

Creating a card page

Now, let’s create a card page. The process for a card page is almost the same as for a list page, but we use a different tpage snippet. Our page number will be 50101 and the name will be Radio Show Card:

Figure 1.30 – Fill in the Radio Show card page as shown

Figure 1.30 – Fill in the Radio Show card page as shown

As we don’t want our card page to be searchable in the web client, we have removed UsageCategory. Additionally, we have renamed the snippet’s GroupName to General; This will be displayed as a FastTab caption to the user.

Note

You can copy and paste most of the definitions from the list page file, or even use File and Save As in Visual Studio Code if you find that faster or easier to use.

Let’s change the launch.json file to this new page and publish the extension again. We can view the page by modifying the launch.json file. Change startupObjectId to 50101 and select AL: Publish without debugging from the Command Palette. The page will look like this:

Figure 1.31 – The Radio Show card page in the Business Central client

Figure 1.31 – The Radio Show card page in the Business Central client

Creating some sample data

Even though we haven’t added all the bells and whistles to our Radio Show table and pages, we can still use them to enter sample data. The Radio Show List page will be the easiest to use for this.

We will now revert the launch.json file so that it runs the 50100 page, as originally defined, and then publish the extension. In the published window, click New; you’ll see the following screen:

Figure 1.32 – Adding a new record to the Radio Show list page

Figure 1.32 – Adding a new record to the Radio Show list page

Enter the data shown in the following table so that we can see what the page looks like when it contains data. Later, once we’ve added more capabilities to our table and pages, some fields will be validated, and some will be either automatically entered or available on a lookup basis. But for now, simply key in each field value. If the data we key in now conflicts with the validations we create later (such as data in referenced tables), we may have to delete this test data and enter new test data later:

No.

Radio Show Type

Name

Run Time

Host Code

Host Name

RS001

TALK

CeCe and Friends

2 hours

CECE

CeCe Grace

RS002

MUSIC

Alec Rocks and Bops

2 hours

ALEC

Alec Benito

RS003

CALL-IN

Ask Cole!

2 hours

COLE

Cole Henry

RS004

CALL-IN

What do you think?

1 hour

WESLEY

Wesley Ernest

RS005

MUSIC

Quiet Times

3 hours

SASKIA

Saskia Mae

RS006

NEWS

World News

1 hour

DAAN

Daan White

RS007

ROCK

Rock Classics

2 hours

JOSEPH

Josephine Black

RS008

TALK

Kristel's Babytalks

1 hour

KRIS

Kristel van Vugt

Table 1.3 – Test data

Creating a list report

To create a report, we will use the report snippet treport and create the 50100 Radio Shows report.

Note

Testing this report will result in an error message occurring if the sample data hasn’t been created yet.

Type 50100 into the Id and Radio Shows into MyReport:

Figure 1.33 – Edited report template

Figure 1.33 – Edited report template

If we want users to be able to execute our report from Business Central, we also need to enable a search so that they can find our report. We will do that using the UsageCategory and ApplicationArea properties. The UsageCategory property will determine where the report will be listed, while the ApplicationArea property will determine the access level a user requires to be able to execute the report:

 Figure 1.34 – Properties to show pages and reports in the search

Figure 1.34 – Properties to show pages and reports in the search

Note

We will learn more about these properties later in Chapter 4, in the Page Searchability section.

The SourceTableName value (visible in Figure 1.32) for our report is the Radio Show table. The columns are the fields from this table. Spaces and special characters are not allowed in column names for reports.

After selecting the columns and removing any unnecessary elements (requestpage and var) from the snippet, our report code above rendering should look as follows:

 Figure 1.35 – Columns in the “Radio Shows” report

Figure 1.35 – Columns in the “Radio Shows” report

Generating the layout

Now that we’ve defined our dataset, we can create the layout. Business Central supports RDLC, which can be edited in Visual Studio, SQL Report Builder, Microsoft Excel, and Microsoft Word.

There is no limit to the number or variety of layouts that can be defined for each report, though a single rendering layout must be defined as the default using DefaultRenderingLayout. In our example, we will create one of each of the three available types (RDLC, Word, and Excel):

 Figure 1.36 – Rendering layouts

Figure 1.36 – Rendering layouts

To generate the layouts, we need to package our application. We can do this from the Command Palette by running AL: Package:

 Figure 1.37 – Building the package to generate the layout

Figure 1.37 – Building the package to generate the layout

This screenshot shows the generated RDLC, which is essentially similar to XML syntax:

 Figure 1.38 – RDLC layout

Figure 1.38 – RDLC layout

Let’s see if we can run our report. To do that, we will publish our extension without startupObjectId:

 Figure 1.39 – launch.json

Figure 1.39 – launch.json

In the Business Central session, we will use the search box and type in the word radio, which will show our report:

 Figure 1.40 – Searching for our new report in the client

Figure 1.40 – Searching for our new report in the client

When you click on the report and select Preview & Close, you should see an empty layout.

Designing the layout

In this book, we will focus on Excel reports, so we will remove the RDLC and Word files and associated properties in the report. We will use the DefaultRenderingLayout property to make Excel the default report format choice. Follow these steps:

  1. Right-click on the RadioShows.xlsx file and open it in Microsoft Excel:
 Figure 1.41 – Opening the Excel layout outside of VS Code

Figure 1.41 – Opening the Excel layout outside of VS Code

Excel will open; you should see the dataset of the Radio Shows report on a sheet labeled Data. Every Excel layout must include two elements: the datasheet and the data table. These elements form the basis of the layout by defining the flattened data generated by the report that you can work with. This data table is the basis of the calculations and visualizations that you will want to present on the other sheets. Don’t change the name, add, modify, or delete the datasheet, data table, or columns as these are controlled by the report dataset definition.

 Figure 1.42 – Datasheet in our Excel workbook

Figure 1.42 – Datasheet in our Excel workbook

  1. In Excel, click the Insert tab in the ribbon and choose PivotTable:
 Figure 1.43 – The PivotTable button

Figure 1.43 – The PivotTable button

  1. Choose From Table/Range with the default options of Data and New worksheet. Then, click OK:

 Figure 1.44 – Adding a PivotTable in Excel

Figure 1.44 – Adding a PivotTable in Excel

  1. Select the RadioShowType, Name, AverageListeners, and AdvertisingRevenue columns. Drag and drop Count of AverageListeners and Count of AdvertisingRevenue to Values from the Rows box on the right:
Figure 1.45 – Populating PivotTable Fields

Figure 1.45 – Populating PivotTable Fields

  1. After saving and closing the Microsoft Excel document, we can publish our extension, search for the report, and select Download:
 Figure 1.46 – Preview of the Pivot-style report in Excel

Figure 1.46 – Preview of the Pivot-style report in Excel

There is much more to come. All we’ve done so far is scratch the surface. But by now, you should have a pretty good overview of the development process for Business Central.

Note

You will be in especially good shape if you’ve been able to follow along on your system, doing a little experimenting along the way.

Other Business Central object types

We’ll finish our introductory review by covering the Business Central object types that haven’t been covered in detail yet.

Extension data types

Similar to the table and page objects, the tableextension and pageextension objects allow you to define additional fields in the database and display them to the user:

  • Table extensions are connected to existing tables and share the same primary key values. Fields defined in table extensions can be used on any existing page and report that uses the original table.
  • Page extensions allow developers to add new fields, tabs, actions, and FactBoxes to existing pages. You can also use this to hide controls.

Objects of the report and enum type can also be extended:

  • reportextension objects allow developers to add new data items, fields, trigger logic, request page controls, and layouts to existing reports
  • enumextension objects allow developers to add new values within their app-specific ID range

Codeunits

A codeunit object is a container for chunks of AL code to be called from other objects. These chunks of code are called procedures, also referred to as functions or methods. Procedures can be called from any of the other Business Central object types that can contain AL code. Codeunits can also be exposed (published) as web services. This allows the procedures within a published codeunit to be invoked by external routines.

Codeunits are suited structurally to contain only procedures. Even though procedures could be placed in other object types, the other object types have superstructures that relate to their designed primary use, such as pages and reports.

Codeunits act only as containers for AL-coded procedures. They have no auxiliary procedures, no method of direct user interaction, and no predefined processing. Even if we are creating only one or two procedures and they are closely related to the primary activity of a particular object, and if these procedures are needed from both inside and outside of the particular object, the best practice is still to locate the procedures in a codeunit object.

Several codeunits are delivered as part of the standard Business Central product and are just procedure libraries. These codeunits consist completely of utility routines and are generally organized on some functional basis (for example, associated with dimensions, some aspect of manufacturing, or some aspect of warehouse management). Many of these can be found by filtering the codeunit names on the Management and Mgt strings (the same could be said for some of the tables with the Buffer string in their name). When we customize a system, we should create procedure library codeunits to consolidate our customizations and make software maintenance easier. Some developers create libraries of their favorite special procedures and include a custom procedure library codeunit in the systems on which they work.

Queries

Queries are objects of the query type. Their purpose is to create extracted sets of data from the Business Central database and do so very efficiently. Business Central queries translate directly into T-SQL query statements and run on the SQL Server side rather than on the Business Central Service Tier. A query can extract data from a single table or multiple tables. In the process of extracting data, a query can make different types of joins (inner join, outer join, or cross join), filters, calculate FlowFields (special Business Central calculations that will be discussed in detail in Chapter 3, Data Types and Table Fields), sorts, and create sums and averages. Queries obey the Business Central data structure business logic.

Pages can open queries the very same way they would open other pages. A query is then rendered like a list page, providing a practical analysis view. Other than that, the output of a query can be a CSV file (useful for Excel charts), an XML file (for charts or external applications), or an OData file for a web service. Queries can be published for web service access, similar to pages and codeunits, and as RESTful APIs. The results of a query can also be viewed by pages (as described in Chapter 5, Reports and Queries), but they are especially powerful when output to charts. With a little creativity, a query can also be used to feed data to a report via the use of a temporary table to hold the query’s results.

XMLports

XMLports are a tool for importing and exporting data. Objects of the xmlport type handle both XML structured data and other external text data formats. XML (eXtensible Markup Language) is the de facto standard format for exchanging data between dissimilar systems. For example, XMLports could be used to communicate between our Business Central ERP system and our accounting firm’s financial analysis and tax preparation system.

XML is designed to be extensible, which means that we can create or extend the definition, so long as we communicate the defined XML format to our correspondents. There is a standard set of syntax rules to which XML formats must conform. Despite the rise of JSON, XML still finds applications in specific domains, such as web services communications.

The non-XML text data files handled by XMLports fall into two categories. One is known as comma-separated value or comma-delimited files (they usually have a .csv file extension). Of course, the delimiters don’t have to be commas. The other category is fixed format, in which the length and relative position of each field are predefined.

XMLports can contain AL logic for any type of appropriate data manipulation, either when importing or exporting. Functions such as editing, validating, combining, and filtering can be applied to the data as it passes through an XMLport.

Development backups and documentation

As with any system where we can do development work, paying careful attention to documentation and backing up our work is very important. Visual Studio Code provides a variety of techniques for handling each of these tasks.

The first area where we can place documentation is in line with modified AL code. Individual comment lines can be created by starting the line with double forward slashes, //. Whole sections of comments (or commented-out code) can be created by enclosing the section with /* ... */. Depending on the type of object and the nature of the specific changes, we should generally annotate each change inline with forward slashes rather than wherever the code is touched so that all the changes can be easily identified by the next developer who will work on this code.

Tip

The easiest way to add – and remove – double forward slashes at the beginning of the current line or for a marked range of lines is to press Ctrl + / or Ctrl + #, depending on your environment’s language.

The best documentation resides outside of our source code. Visual Studio Code has built-in support for Git, which means that we can use any source code control system that supports Git repositories, including, but not limited to, GitHub, GitLab, or Azure DevOps.

There are some great resources on how to get started with Git, such as the ones we mentioned earlier in this chapter. A good explanation of using Git source control in VS Code can be found at https://code.visualstudio.com/docs/sourcecontrol/overview.

In short, when doing development in Business Central VS Code, everything we have learned earlier about good documentation practices applies. This holds true, regardless of whether development involves new work or modifying existing logic.

Summary

In this chapter, we covered some basic definitions of terms related to Business Central and VS Code. We followed this by introducing 12 Business Central object types (tables, table extensions, pages, page extensions, reports, report extensions, profiles, codeunits, queries, enums, enum extensions, and XMLports). We introduced table, page, and report creation through review and hands-on use and began a Business Central application for managing Radio Show at WTDU. Finally, we briefly looked at the tools that we can use to integrate with external entities and discussed how different types of backups and documentation are handled in VisuVS Code.

Now that we’ve covered the basics, we can dive into primary object types in the next few chapters. In the next chapter, we will focus on tables – the foundation of any Business Central system.

Questions

Answer the following questions to test your knowledge of this chapter:

  1. An ERP system such as Business Central includes several functional areas. Which of the following are part of Business Central? Choose four:
    • Manufacturing
    • Sales order processing
    • Inventory
    • Computer-aided design (CAD)
    • Financial management

    ANSWER: Manufacturing, sales order processing, inventory, and financial management

  2. Business Central development is done in Visual Studio Professional. True or false?

    ANSWER: False

  3. Match the following page types and descriptions for Business Central:

    Journal Audit trail

    Ledger Validation process

    Register Invoice

    Document Transaction entries

    Posting History

    ANSWER: Journal – Transaction entries, Ledger – History, Register – Audit trail, Document – Invoice, Posting – Validation process

  4. You can create extensions using VS Code in a Linux or macOS environment. True or false?

    ANSWER: True

  5. Which of the following are Business Central applications? Choose three:
    • System Application
    • Core Application
    • Sales and Distribution Application
    • Base Application
    • Business Foundation

    ANSWER: System Application, Base Application, and Business Foundation

  6. Which of the following describes Business Central? Choose two:
    • Customizable
    • Includes a storefront module
    • Object-based
    • Azure .NET
    • Object-oriented

    ANSWER: Customizable and object-based

  7. Which are the valid options for environment types that you can connect to in the launch.json file? Choose two:
    • Docker
    • Sandbox
    • Live
    • Production

    ANSWER: Sandbox and production

  8. Symbols are .app files containing metadata for other extensions. True or false?

    ANSWER: True

  9. When working with Excel report layouts, you can update the dataset from Business Central directly in the Data tab. True or false?

    ANSWER: False

  10. Codeunits are the only Business Central objects that can contain procedures. True or false?

    ANSWER: False

  11. Query output can be used as a data item for reports. True or false?

    ANSWERS: True

  12. VS Code with the AL extension is required for Business Central development. True or false?

    ANSWER: True

  13. Which object number range can be assigned to customer-specific objects?
    • 20 – 500
    • 17,000,000 – 37,000,000
    • 150,000 – 200,000
    • 50,000 – 99,999
    • 10,000 – 100,000

    ANSWER: 50,000 – 99,999

  14. XMLports can only process XML-formatted data. True or false?

    ANSWER: False

  15. The work date can only be changed by the system administrator. True or false?

    ANSWER: False

  16. A design pattern is which of the following? Choose two:
    • Reusable code
    • Stripes and plaid together
    • A proven way to solve a common problem
    • UI guidelines

    ANSWER: Reusable code and a proven way to solve common problems

  17. Business Central reports are often generated automatically through the use of a wizard. True or false?

    ANSWER: False

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Work with the new additions to the AL Language, Visual Studio Code, and Business Central
  • Enhance your AL programming skills through real-world examples and best practices curated by industry experts
  • Implement updated best practices for development to build efficient, reliable, and maintainable extensions
  • Purchase of the print or Kindle book includes a free PDF eBook

Description

Business Central opens a world of endless possibilities for custom business logic and functionality through extensions and customizations. For beginners in the AL language, navigating the vast landscape can feel overwhelming. It’s challenging to know where to start and what’s essential to learn. This updated edition offers a concise and well-organized guide, featuring hands-on exercises to support a successful learning journey. You’ll get to grips with the basics of Business Central and how to create your first Visual Studio Code project with the AL language. As you learn about the table data structure, simple and complex data types, relationships, validation, and data flow, you’ll be able to add and extend tables to your project. Progressively, you'll uncover the intricacies of user interfaces with pages, create advanced Excel report layouts, and harness the power of data queries. Immersing yourself in the AL language syntax, you’ll start with variables, methods, procedures, and statements. You'll explore advanced topics to create business logic such as FlowFields, filtering, CRUD methods, interactions between object types, and different API interfaces that can be created using the AL language. By the end of this book, you’ll be equipped to build fully featured, robust extensions and custom capabilities for Business Central.

Who is this book for?

This book is for anyone who wants to learn about Microsoft Dynamics 365 Business Central's powerful and extensive development capabilities. ERP consultants and managers of Business Central development will also find this book helpful. Although you aren't expected to have previously worked with Microsoft Dynamics Business Central, having a basic understanding of programming and familiarity with business applications software will help you understand the concepts covered in this book.

What you will learn

  • Set up your first AL development environment with Visual Studio Code
  • Understand the data structure and flow of Business Central
  • Design, build, and extend Table, Page, Report, Codeunit, Query, and XMLport objects in Business Central
  • Develop AL code for business logic and data manipulation in Visual Studio Code
  • Use Excel layouts to report Business Central data
  • Integrate Business Central with external systems using API web services
  • Implement multi-language in your own extension
  • Debug and troubleshoot Business Central applications
Estimated delivery fee Deliver to Sweden

Premium delivery 7 - 10 business days

€17.95
(Includes tracking information)

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Oct 31, 2024
Length: 466 pages
Edition : 7th
Language : English
ISBN-13 : 9781803236414
Vendor :
Microsoft

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Product feature icon AI Assistant (beta) to help accelerate your learning
OR
Modal Close icon
Payment Processing...
tick Completed

Shipping Address

Billing Address

Shipping Methods
Estimated delivery fee Deliver to Sweden

Premium delivery 7 - 10 business days

€17.95
(Includes tracking information)

Product Details

Publication date : Oct 31, 2024
Length: 466 pages
Edition : 7th
Language : English
ISBN-13 : 9781803236414
Vendor :
Microsoft

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
€189.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
€264.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
Banner background image

Table of Contents

10 Chapters
Chapter 1: Introduction to Business Central Chevron down icon Chevron up icon
Chapter 2: Tables Chevron down icon Chevron up icon
Chapter 3: Data Types and Table Fields Chevron down icon Chevron up icon
Chapter 4: Pages – The Interactive Interface Chevron down icon Chevron up icon
Chapter 5: Reports and Queries Chevron down icon Chevron up icon
Chapter 6: Introduction to AL Chevron down icon Chevron up icon
Chapter 7: Intermediate AL Chevron down icon Chevron up icon
Chapter 8: Extensibility beyond AL Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon
Other Books You May Enjoy Chevron down icon Chevron up icon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is the delivery time and cost of print book? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela
What is custom duty/charge? Chevron down icon Chevron up icon

Customs duty are charges levied on goods when they cross international borders. It is a tax that is imposed on imported goods. These duties are charged by special authorities and bodies created by local governments and are meant to protect local industries, economies, and businesses.

Do I have to pay customs charges for the print book order? Chevron down icon Chevron up icon

The orders shipped to the countries that are listed under EU27 will not bear custom charges. They are paid by Packt as part of the order.

List of EU27 countries: www.gov.uk/eu-eea:

A custom duty or localized taxes may be applicable on the shipment and would be charged by the recipient country outside of the EU27 which should be paid by the customer and these duties are not included in the shipping charges been charged on the order.

How do I know my custom duty charges? Chevron down icon Chevron up icon

The amount of duty payable varies greatly depending on the imported goods, the country of origin and several other factors like the total invoice amount or dimensions like weight, and other such criteria applicable in your country.

For example:

  • If you live in Mexico, and the declared value of your ordered items is over $ 50, for you to receive a package, you will have to pay additional import tax of 19% which will be $ 9.50 to the courier service.
  • Whereas if you live in Turkey, and the declared value of your ordered items is over € 22, for you to receive a package, you will have to pay additional import tax of 18% which will be € 3.96 to the courier service.
How can I cancel my order? Chevron down icon Chevron up icon

Cancellation Policy for Published Printed Books:

You can cancel any order within 1 hour of placing the order. Simply contact customercare@packt.com with your order details or payment transaction id. If your order has already started the shipment process, we will do our best to stop it. However, if it is already on the way to you then when you receive it, you can contact us at customercare@packt.com using the returns and refund process.

Please understand that Packt Publishing cannot provide refunds or cancel any order except for the cases described in our Return Policy (i.e. Packt Publishing agrees to replace your printed book because it arrives damaged or material defect in book), Packt Publishing will not accept returns.

What is your returns and refunds policy? Chevron down icon Chevron up icon

Return Policy:

We want you to be happy with your purchase from Packtpub.com. We will not hassle you with returning print books to us. If the print book you receive from us is incorrect, damaged, doesn't work or is unacceptably late, please contact Customer Relations Team on customercare@packt.com with the order number and issue details as explained below:

  1. If you ordered (eBook, Video or Print Book) incorrectly or accidentally, please contact Customer Relations Team on customercare@packt.com within one hour of placing the order and we will replace/refund you the item cost.
  2. Sadly, if your eBook or Video file is faulty or a fault occurs during the eBook or Video being made available to you, i.e. during download then you should contact Customer Relations Team within 14 days of purchase on customercare@packt.com who will be able to resolve this issue for you.
  3. You will have a choice of replacement or refund of the problem items.(damaged, defective or incorrect)
  4. Once Customer Care Team confirms that you will be refunded, you should receive the refund within 10 to 12 working days.
  5. If you are only requesting a refund of one book from a multiple order, then we will refund you the appropriate single item.
  6. Where the items were shipped under a free shipping offer, there will be no shipping costs to refund.

On the off chance your printed book arrives damaged, with book material defect, contact our Customer Relation Team on customercare@packt.com within 14 days of receipt of the book with appropriate evidence of damage and we will work with you to secure a replacement copy, if necessary. Please note that each printed book you order from us is individually made by Packt's professional book-printing partner which is on a print-on-demand basis.

What tax is charged? Chevron down icon Chevron up icon

Currently, no tax is charged on the purchase of any print book (subject to change based on the laws and regulations). A localized VAT fee is charged only to our European and UK customers on eBooks, Video and subscriptions that they buy. GST is charged to Indian customers for eBooks and video purchases.

What payment methods can I use? Chevron down icon Chevron up icon

You can pay with the following card types:

  1. Visa Debit
  2. Visa Credit
  3. MasterCard
  4. PayPal
What is the delivery time and cost of print books? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela