Exercise - Create the reward level table object
Scenario
The Reward Level table will store the different reward levels and the points that are required to acquire an award level.
The table consists of two fields:
Level
Minimum Reward Points
Create the Reward Level table object
To create the Reward Level table object, follow these steps:
Create a new .al file in the src folder.
To create a new table in your extension, first create a new file. You can create a new file by selecting the New File button in the side bar of Visual Studio Code.
Make sure that the filename ends with .al. In this example, you might want to use the name RewardLevel.Table.al.
Add the code to the table. Copy the following code and paste it in the RewardLevel.Table.al file.
table 50100 "Reward Level"
{
Caption = 'Reward Level';
TableType = Normal;
DataClassification = CustomerContent;
fields
{
field(1; Level; Text[20])
{
Caption = 'Level';
DataClassification = CustomerContent;
}
field(2; "Minimum Reward Points"; Integer)
{
Caption = 'Minimum Reward Points';
DataClassification = CustomerContent;
MinValue = 0;
NotBlank = true;
trigger OnValidate();
var
RewardLevel: Record "Reward Level";
tempPoints: Integer;
begin
tempPoints := "Minimum Reward Points";
RewardLevel.SetRange("Minimum Reward Points", tempPoints);
if not RewardLevel.IsEmpty() then
Error('Minimum Reward Points must be unique');
end;
}
}
keys
{
key(PK; Level)
{
Clustered = true;
}
key("Minimum Reward Points"; "Minimum Reward Points") { }
}
trigger OnInsert();
begin
Validate("Minimum Reward Points");
end;
trigger OnModify();
begin
Validate("Minimum Reward Points");
end;
}