Skip to main content

AL Development 01 - How to Develop New Table in Database?

Hello readers,

As we know to develop any solution in Business Central we must start working on AL Code Extension so from this blog you will get to know the detailed step how to create a table through AL Code in business Central.

Requirement: Need to create a new table with below fields:


Now let’s Start:
Try to keep a naming standard for your projects;
As I am using the combination of Table description +Table-ID, you can use your own naming convention.

So, my table file name is: My_Table50129.al



AL provides a list of the snippets to make it easy for developers to add objects in extension. Snippet for getting a table layout use snippet ttable (here we have to t as prefix for every type of object we want to create in AL) as shown below:



Now Assign the ID and name of the table as below:



As you select the ttable from the list a default table design structure is created as shown below:





You can divide the whole table into 4 Sections -
· Field Section - This section contains all the fields that you want to add to the table.
· Key Section - All Primary and Secondary key can be added to the following areas.
· Global Variable Section - All global variables are added in this section.
· Table Trigger Section - All base table triggers are available in the areas. If required, you can add code in this section as previously we are doing in CAL.
Plus, if you don't need any of these sections you can delete that section (which you cannot do in NAV / CAL).
Let's add fields in the table as discussed above and see how easy it. For adding a new field, you can also use snipped tfield as shown below:



The area between {} inside a field, where you can add field properties. But in NAV you can see using Shift+F4, but in AL you can use Ctrl + Spacebar, to see all field list, as shown below.



To show how to write functions and how we can use table trigger I had created a function UpdateCreatedOn and called it onInsert trigger of the table which will update the “creation date” field automatically as workdate when any record is inserted into the table.
Snippet for new procedure:

This how our procedure/function will look

Now calling the function OnInsert trigger:

Now our table design is completed now we can save the table and create the .app extension for this table.
Use Ctrl+Shift+P to view the command pallet which are available.

Comments

Popular posts from this blog

Improved performance features of Business Central 17

  In the training I’ve done to some partners last week, when talking about performances I shared an example of an extension with 3 features that I think are not so well known but that have a significant impact on how your code performs, expecially on a SaaS environment. That extension used the following features: Partial record loading Temporary Tables QueryCategory The  Partial record  capability  is a new feature available starting from Dynamics 365 Business Central 2020 Wave 2 (v17) and I think it’s one of my top personal desiderata from years. This feature permits you to load only the needed fields of a recordset (when accessing a data source) instead of loading the entire set of fields. This is particularly useful on reports and OData pages because you can avoid to do a SELECT * (plus JOINS with all the extension’s tables) and instead doing a SELECT of only the fields you need. Now you can do something like: procedure TestPartialRecord(): Decimal ...

Custom sheet name in RDLC Reports

Hi Readers, In this article we are going to discuss how to change the excel sheet name while using base Navision SAVEASEXCEL functionality. Applicable for RDLC reports of Navision and SSRS reports. Let’s say we have the following report that shows total sales by product category by territory:   When we export this report to Excel, we’d like each territory to appear in its own worksheet and each worksheet named after its territory: How do we make this work? Easy! 1) Put every group on its own page. 2) name each page using the same field the group uses. Step 1: Put each group on its own page To put each group on its own page, open the group’s property window. Then, in the Page Breaks category, put a check mark in the Between each instance of a group check box. Click OK to complete this step. Step 2: Name the pages of the group With the group selected in the Row Group s panel, press F4 to open the Properties window. Next, expand the Group ...

UPGRADE CUSTOMIZATIONS TO V2 EXTENSION (Application and Data)

From Navision 2018 Onwards, Navision only support v2 Extension. Dynamic Navision Extension will make upgrade easier. If customizations are converted into V2 extension that means v2 Extension consist upgraded Data as well as customizations, also it will be easy to upgrade into new version of Navision and apply CU updates. Below are the detailed steps to upgrade customizations into Navision 2018 v2 Extensions .  1) you have Customized database in Microsoft Dynamics Navision 2018. 2) Create the new table for each table that is customized or also for customized field in standard table but while creating table for standard table, add the primary key and customized field with same ID and Name in new table. For E.g.: I have created 1 table “Person” and 2 Customized Field (Test, Doc No) in “Sales Header”. Now create 2 New tables in 2018.  · Upg Sales Header -> Two base field (PK) and customized field -> Same ID and add primary key. Refer be...