You are on page 1of 9

How to create Table

This explains how to create new table in Visual Studio Code.


To create table, first you need to create separate folder for your project in visual studio
code.

Open the Visual Studio Code

1. Press “Ctrl+Shift+P” to get the Commands


2. From the Commands select “AL: Go!” to create a new folder

3. Type the folder name at the end of your file path and then press Enter
4. You will get your the folder in Explorer
5. Enter your server name in launch.json file

6. Click on the “Ctrl+Shift+P” to get the commands


7. From the commands select the “AL: Download symbols” to download symbols.
Symbols which contain all the default object in Business Central (such as Tables,
Pages, Codeunits, Reports, Queries, XMLPorts, and Menusuits)
8. Enter your Username and then press enter

9. Enter your password and then press enter

10.Once it is downloaded successfully, you will get the following message in your
output screen

11.Create a new file inside the folder with .al extension


12.Type “tt” to get the Snippet commands of table.
13.From that command select the “ttable” to get the Snippet of table

14.This is the snippet for table

15.To create table, First you need to create Table ID and Table Name


16.Then create field inside the fields command
17.Type “tf” to get the Snippet type of fields.

18.This is the snippet for table fields.


19.To create field you have to give Field ID, Field Name and Datatype for each
field
20.Inside that field add an optional Caption For our example:                                      
Caption = ‘Employee ID’;

21.Add primary key for your table inside the Keys


22.For table you have to create permissionset
23.Create new file inside the folder as permission with extension “.xml”
24.Type “tp” to get the permissionset snippets
25.Select “tpermissionsetcollection (CRS)” command from the snippet

26.Enter the RoleID and RoleName
27.Type the Table ID inside the ObjectID, that you want to give permission
28.Set “1” to Read, Insert, Modify, Delete, Excute Permissions as follow below
screenshot                                                                                                                   
“0”- False  &  “1”-True                                                                              
29.By following this procedure you can create as many fields as you want in a table
30.To build the extension press “Ctrl+Shift+B”
31.Once the Build process is completed successfully you will get Success messagein
your output screen
32.The corresponding .app will be saved to the folder you created in step 4

33. Table is created successfully


Sample AL code For Table:

table 33001231 PF
{
DataCaptionFields = "Effective Date";
LookupPageId = "PF List";
DrillDownPageId = "PF List";

fields
{
field(1;Id;Integer)
{
}
field(2;"Effective Date";Date)
{

trigger OnValidate();
begin
//Rev1
PF.RESET;
PF.SETRANGE("Effective Date","Effective Date");
if PF.FINDFIRST then
ERROR('Record exists with Effective Date%1',"Effective Date");
//Rev1
end;
}
field(3;"Employer Contribution";Decimal)
{
DecimalPlaces = 2:2;
MinValue = 0;
}
field(4;"Employee Contribution";Decimal)
{
DecimalPlaces = 2:2;
MinValue = 0;
}
field(5;"Rounding Amount";Decimal)
{
MinValue = 0;
}
field(6;"Rounding Method";Option)
{
OptionMembers = Nearest,Up,Down;
}
keys
{
key(Key1;Id)
{
}
}

fieldgroups
{
}

trigger OnInsert();
begin
if PF.FIND('+') then
Id := PF.Id + 1
else
Id := 1;
end;

var
PF : Record PF;
}

You might also like