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.
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).
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.
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:
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:
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.
Now calling the function OnInsert trigger:
Comments
Post a Comment