Book Image

Microsoft Dynamics 365 Business Central Cookbook

By : Michael Glue
Book Image

Microsoft Dynamics 365 Business Central Cookbook

By: Michael Glue

Overview of this book

Microsoft Dynamics 365 Business Central is a complete business management solution that can help you streamline business processes, connect individual departments in your company, and enhance customer interactions. Ok. That first part was really professional sounding, right? Now, let’s get into what this cookbook is going to do for you: put simply, it’s going to help you get things done. This book will help you get to grips with the latest development features and tools for building applications using Business Central. You’ll find recipes that will guide you in developing and testing applications that can be deployed to the cloud or on-premises. For the old-schoolers out there, you’ll also learn how to take your existing Dynamics NAV customizations and move them to the new AL language platform. Also, if you haven’t figured it out already, we’re going to be using very normal language throughout the book to keep things light. After all, developing applications is fun, so why not have fun learning as well!
Table of Contents (11 chapters)

Creating basic entities

Adding basic entities to your AL application is easy. We're going to take a look at two of them in this recipe: tables and pages. We'll create a new table to track television shows (come on, we need to have some fun with this, right!?) and an associated card and list page.

Getting ready

You're going to need an AL project to work in that's connected to a development sandbox. We will continue to build on the project that we started in this chapter. You can download it from the GitHub link at the start of this chapter.

How to do it...

  1. Open your AL project folder in Visual Studio Code. If you have not done so already, delete HelloWorld.al.
  2. In the Visual Studio Code Explorer, right-click and select New File. Name this file Television Show.al.

Repeat this process and create two more files:

    • Television Show List.al
    • Television Show Card.al
All files that contain AL code need to have an .al extension.
  1. Let's define the new table.
You can quickly add the basic structure for a table and field by using the ttable and tfield snippets. Do this by typing in your chosen snippet name and pressing Tab.

In Explorer, select Television Show.al. In the Editor tab, enter the following:

table 50100 "Television Show"
{
fields
{
field(1; Code; Code[20])
{
NotBlank = true;
}
field(2; Name; Text[80])
{
}
field(3; Synopsis; Text[250])
{
}
field(4; Status; Option)
{
OptionCaption = 'Active,Finished';
OptionMembers = Active,Finished;
}
field(5; "First Aired"; Date)
{
}
}

keys
{
key(PK; Code)
{
Clustered = true;
}
}
}

Make sure you save your changes.

  1. Now, let's create a card to display the detailed information for our Television Show records.
You can quickly add the basic structure for a card page by using the tpage snippet. There are multiple types of page snippets, so be sure to select the correct one.

In Explorer, select Television Show Card.al. In the Editor tab, enter the following:

page 50100 "Television Show Card"
{
PageType = Card;
SourceTable = "Television Show";
DelayedInsert = true;

layout
{
area(Content)
{
group(General)
{
field(Code; Code)
{
ApplicationArea = All;
}
field(Name; Name)
{
ApplicationArea = All;
}
field(Synopsis; Synopsis)
{
ApplicationArea = All;
}
field(Status; Status)
{
ApplicationArea = All;
}
field("First Aired"; "First Aired")
{
ApplicationArea = All;
}
}
}
}
}
  1. Now, we'll build a list page to display the records from our new table.
Only show the most relevant and frequently used information on your list pages.

In Explorer, select Television Show List.al. In the Editor tab, enter the following:

page 50101 "Television Show List"
{
PageType = List;
ApplicationArea = All;
UsageCategory = Lists;
Editable = false;
CardPageId = "Television Show Card";
SourceTable = "Television Show";

layout
{
area(Content)
{
repeater(Group)
{
field(Code; Code)
{
ApplicationArea = All;
}
field(Name; Name)
{
ApplicationArea = All;
}
field(Status; Status)
{
ApplicationArea = All;
}
}
}
}
}
In order to make your pages (and reports) searchable in the Business Central Web Client, you need to populate ApplicationArea and UsageCategory in the AL object file.
  1. Our basic application is ready to be published for testing. In the launch.json file, set the following properties:
"startupObjectId": 50101
"startupObjectType": "Page"
  1. Press F5 to publish the application to your development sandbox. Your web browser will open and, once you log in, you will be presented with your new Television Show List page:
  1. Of course, there is not much to see until you enter some records. Try that out by clicking the +New button in the ribbon; the Television Show Card should open:

How it works...

We created a basic Business Central application and published it to our development sandbox.

Creating a table allows us to define what data we will capture in our application. We can define a number of properties for each table and field.

In order to display the data in the table, we need to create pages. These allow the user to interact with the data in our application. A list page is the first page that the user will get to when they want to access the data. From this list, they can search, filter existing data, create new data, modify data, and even delete data. When more detailed information is required, the user can navigate from the list page to the card page, which is meant to show more detailed information and actions regarding the data.

See also