อ่านโค้ด เข้าใจเหตุผล
แล้วลองด้วยตัวเอง
ชุดฝึก AL สำหรับบท 12–15 พร้อม source และวิธีตรวจผล
ก่อนเริ่มทดลอง
ต้องมีโปรเจกต์จาก AL: Go!, VS Code + AL Language, แล็บ on-premises หรือ online Sandbox ที่มีสิทธิ์พัฒนา และ Symbols ตรงกับเป้าหมาย ตัวอย่างใช้ object/field IDs ช่วง 50100–50102 เฉพาะเมื่อองค์กรอนุญาตและไม่ชนของเดิม
- อ่าน บท 12 เพื่อสร้าง app.json และ launch.json ของเป้าหมายจริง มีตัวอย่าง launch.json พร้อมคำอธิบายในบท 12 และต้องปรับตามระบบจริง ไม่มี secret ในชุดนี้
- ดาวน์โหลดและอ่าน README วิธีติดตั้งและ test cases วาง source ใน src/ ของโปรเจกต์ ห้ามมีสำเนา .al ซ้ำ
- Download Symbols → AL: Package → ตรวจ Problems → เมื่อ compile ผ่านจึง publish ไป Sandbox และบันทึกผลจริง
สถานะการตรวจ: source ตัวอย่าง ยังไม่ compile/run กับ Business Central จริง
การตรวจเว็บไซต์และไฟล์ดาวน์โหลดไม่ใช่การทดสอบ AL compiler สูตรนี้ไม่รวมภาษี ส่วนลด สกุลเงิน หรือการ Post เอกสาร
การตรวจเว็บไซต์และไฟล์ดาวน์โหลดไม่ใช่การทดสอบ AL compiler สูตรนี้ไม่รวมภาษี ส่วนลด สกุลเงิน หรือการ Post เอกสาร
StartBCPractice.Table.al
กำหนด fields และ primary key ของข้อมูลฝึก
table 50102 "SBC Practice"
{
Caption = 'StartBC practice';
DataClassification = CustomerContent;
fields
{
field(1; "No."; Code[20])
{
Caption = 'No.';
NotBlank = true;
}
field(2; Description; Text[100])
{
Caption = 'Description';
}
}
keys
{
key(PK; "No.")
{
Clustered = true;
}
}
}
StartBCPractice.Page.al
สร้าง List page ที่ผูก SourceTable และ Rec
page 50102 "SBC Practice List"
{
Caption = 'StartBC practice records';
PageType = List;
SourceTable = "SBC Practice";
ApplicationArea = All;
UsageCategory = Lists;
layout
{
area(Content)
{
repeater(Records)
{
field("No."; Rec."No.")
{
ApplicationArea = All;
ToolTip = 'Specifies the unique code for a training record.';
}
field(Description; Rec.Description)
{
ApplicationArea = All;
ToolTip = 'Specifies the description of the training record.';
}
}
}
}
}
StartBCPractice.PermissionSet.al
ให้สิทธิ์เฉพาะข้อมูลและหน้าฝึกสำหรับผู้ใช้ที่ได้รับมอบหมาย
permissionset 50102 "SBC PRACTICE"
{
Assignable = true;
Caption = 'StartBC practice records';
Permissions = tabledata "SBC Practice" = RIMD,
table "SBC Practice" = X,
page "SBC Practice List" = X;
}
StartBCCalculation.Codeunit.al
รับ Decimal ตรวจค่าติดลบ และคืนผลปัดสองตำแหน่ง
codeunit 50100 "SBC Calculation"
{
procedure CalculateAmount(Quantity: Decimal; UnitPrice: Decimal): Decimal
begin
if Quantity < 0 then
Error(NegativeQuantityErr);
if UnitPrice < 0 then
Error(NegativePriceErr);
exit(Round(Quantity * UnitPrice, 0.01));
end;
var
NegativeQuantityErr: Label 'Quantity must be zero or greater.';
NegativePriceErr: Label 'Unit price must be zero or greater.';
}
StartBCExercise.Page.al
ป้อนจำนวนและราคา เรียก Codeunit ผ่าน Action โดยไม่ใช้ SourceTable
page 50101 "SBC Calculation Exercise"
{
PageType = Card;
ApplicationArea = All;
UsageCategory = Tasks;
Caption = 'StartBC calculation exercise';
layout
{
area(Content)
{
group(Inputs)
{
Caption = 'Inputs';
field(QuantityInput; Quantity)
{
ApplicationArea = All;
Caption = 'Quantity';
ToolTip = 'Specifies a nonnegative training quantity.';
}
field(PriceInput; UnitPrice)
{
ApplicationArea = All;
Caption = 'Unit price';
ToolTip = 'Specifies a nonnegative training price.';
}
field(AmountOutput; Amount)
{
ApplicationArea = All;
Caption = 'Amount';
Editable = false;
ToolTip = 'Shows the calculated training amount.';
}
}
}
}
actions
{
area(Processing)
{
action(CalculateTraining)
{
Caption = 'Calculate';
ApplicationArea = All;
Image = Calculate;
ToolTip = 'Calculates the amount from the current inputs.';
trigger OnAction()
var
Calculation: Codeunit "SBC Calculation";
begin
Amount := Calculation.CalculateAmount(Quantity, UnitPrice);
end;
}
}
}
trigger OnOpenPage()
begin
Quantity := 2;
UnitPrice := 150;
end;
var
Quantity: Decimal;
UnitPrice: Decimal;
Amount: Decimal;
}
StartBCCustomer.TableExt.al
เพิ่ม Text[100] บน Customer สำหรับข้อความฝึก
tableextension 50100 "SBC Customer" extends Customer
{
fields
{
field(50100; "SBC Training Note"; Text[100])
{
Caption = 'Training note';
DataClassification = CustomerContent;
}
}
}
StartBCCustomerCard.PageExt.al
แสดงฟิลด์บน Customer Card และเรียก Codeunit จากปุ่ม
pageextension 50100 "SBC Customer Card" extends "Customer Card"
{
layout
{
addlast(General)
{
field(SBCTrainingNote; Rec."SBC Training Note")
{
ApplicationArea = All;
ToolTip = 'Specifies a note used only for the StartBC training exercise.';
}
}
}
actions
{
addlast(Processing)
{
action(SBCShowTrainingAmount)
{
Caption = 'Calculate training amount';
ApplicationArea = All;
Image = Calculate;
ToolTip = 'Calculates a training amount without posting a document.';
trigger OnAction()
var
Calculation: Codeunit "SBC Calculation";
begin
Message(TrainingAmountMsg, Calculation.CalculateAmount(2, 150));
end;
}
}
}
var
TrainingAmountMsg: Label 'Training amount: %1';
}