StartBC.comค้นหาบทเรียน

อ่านโค้ด เข้าใจเหตุผล
แล้วลองด้วยตัวเอง

ชุดฝึก AL สำหรับบท 12–15 พร้อม source และวิธีตรวจผล

ดาวน์โหลดทั้งชุด .zip ↓

ก่อนเริ่มทดลอง

ต้องมีโปรเจกต์จาก AL: Go!, VS Code + AL Language, แล็บ on-premises หรือ online Sandbox ที่มีสิทธิ์พัฒนา และ Symbols ตรงกับเป้าหมาย ตัวอย่างใช้ object/field IDs ช่วง 50100–50102 เฉพาะเมื่อองค์กรอนุญาตและไม่ชนของเดิม

  1. อ่าน บท 12 เพื่อสร้าง app.json และ launch.json ของเป้าหมายจริง มีตัวอย่าง launch.json พร้อมคำอธิบายในบท 12 และต้องปรับตามระบบจริง ไม่มี secret ในชุดนี้
  2. ดาวน์โหลดและอ่าน README วิธีติดตั้งและ test cases วาง source ใน src/ ของโปรเจกต์ ห้ามมีสำเนา .al ซ้ำ
  3. Download Symbols → AL: Package → ตรวจ Problems → เมื่อ compile ผ่านจึง publish ไป Sandbox และบันทึกผลจริง
สถานะการตรวจ: source ตัวอย่าง ยังไม่ compile/run กับ Business Central จริง
การตรวจเว็บไซต์และไฟล์ดาวน์โหลดไม่ใช่การทดสอบ AL compiler สูตรนี้ไม่รวมภาษี ส่วนลด สกุลเงิน หรือการ Post เอกสาร

ไปเส้นทาง Developer

StartBCPractice.Table.al

กำหนด fields และ primary key ของข้อมูลฝึก

AL · source file
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.Table.al ↓

StartBCPractice.Page.al

สร้าง List page ที่ผูก SourceTable และ Rec

AL · source file
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.Page.al ↓

StartBCPractice.PermissionSet.al

ให้สิทธิ์เฉพาะข้อมูลและหน้าฝึกสำหรับผู้ใช้ที่ได้รับมอบหมาย

AL · source file
permissionset 50102 "SBC PRACTICE"
{
    Assignable = true;
    Caption = 'StartBC practice records';
    Permissions = tabledata "SBC Practice" = RIMD,
                  table "SBC Practice" = X,
                  page "SBC Practice List" = X;
}
ดาวน์โหลด StartBCPractice.PermissionSet.al ↓

StartBCCalculation.Codeunit.al

รับ Decimal ตรวจค่าติดลบ และคืนผลปัดสองตำแหน่ง

AL · source file
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.';
}
ดาวน์โหลด StartBCCalculation.Codeunit.al ↓

StartBCExercise.Page.al

ป้อนจำนวนและราคา เรียก Codeunit ผ่าน Action โดยไม่ใช้ SourceTable

AL · source file
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;
}
ดาวน์โหลด StartBCExercise.Page.al ↓

StartBCCustomer.TableExt.al

เพิ่ม Text[100] บน Customer สำหรับข้อความฝึก

AL · source file
tableextension 50100 "SBC Customer" extends Customer
{
    fields
    {
        field(50100; "SBC Training Note"; Text[100])
        {
            Caption = 'Training note';
            DataClassification = CustomerContent;
        }
    }
}
ดาวน์โหลด StartBCCustomer.TableExt.al ↓

StartBCCustomerCard.PageExt.al

แสดงฟิลด์บน Customer Card และเรียก Codeunit จากปุ่ม

AL · source file
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';
}
ดาวน์โหลด StartBCCustomerCard.PageExt.al ↓