From MB AL AI Toolkit
AL language best practices, code style, naming conventions, performance rules (SetLoadFields, early filtering, set-based operations, temp tables), error handling with ErrorInfo/TryFunction, and a code-quality checklist for Microsoft Dynamics 365 Business Central. Use whenever editing, reviewing, or generating AL code (`*.al` files) — especially in PTE projects.
How this skill is triggered — by the user, by Claude, or both
Slash command
/mb-al-ai-toolkit:al-best-practices**/*.alThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
- **Indentation**: 4 spaces (no tabs)
table, page, procedure, begin, end)CustomerNo, TotalAmount)Pattern: <ObjectName>.<ObjectType>.al
Examples: CustomerCard.Page.al, SalesPostingMgt.Codeunit.al
I (e.g., IDataProcessor)Impl (e.g., DataProcessorImpl)Handler for event subscriber codeunitsCustomer: Record Customer; // Record type as name
IsValidTransaction: Boolean; // Boolean: Is, Has, Can prefix
TotalAmount: Decimal; // Descriptive purpose
i: Integer; // Loop counter exception
procedure CalculateBalance() // Action verb + subject
procedure ValidateSalesDocument() // Clear intent
procedure GetDefaultPaymentTerms() // Get for retrieval
Order matters — always specify fields first:
// CORRECT
Customer.SetLoadFields("No.", Name, "Balance (LCY)");
Customer.SetRange("Country/Region Code", 'US');
if Customer.FindSet() then
// WRONG - SetLoadFields after filter
Customer.SetRange("Country/Region Code", 'US');
Customer.SetLoadFields("No.", Name); // Too late!
Apply filters before processing:
// Good - filter first
CustLedgerEntry.SetRange("Customer No.", CustomerNo);
CustLedgerEntry.SetRange(Open, true);
CustLedgerEntry.CalcSums("Amount (LCY)");
// Avoid - filtering in loops
if CustLedgerEntry.FindSet() then
repeat
if CustLedgerEntry.Open then // Too late!
TotalAmount += CustLedgerEntry."Amount (LCY)";
until CustLedgerEntry.Next() = 0;
Prefer aggregation over manual loops:
// Use CalcSums
SalesLine.SetRange("Document No.", DocNo);
SalesLine.CalcSums(Amount);
exit(SalesLine.Amount);
// Avoid manual loops
Use temporary tables for in-memory processing:
procedure ProcessData(var TempBuffer: Record "Buffer" temporary)
begin
// Process in memory, write once to database
end;
// Use FindSet for loops
if Customer.FindSet() then
repeat
ProcessCustomer(Customer);
until Customer.Next() = 0;
// Use FindFirst for single records
if Customer.FindFirst() then
procedure ValidateCreditLimit(Customer: Record Customer; Amount: Decimal)
var
ErrorInfo: ErrorInfo;
begin
if Amount > Customer."Credit Limit (LCY)" then begin
ErrorInfo.Title := 'Credit Limit Exceeded';
ErrorInfo.Message := StrSubstNo('Amount %1 exceeds limit %2.',
Amount, Customer."Credit Limit (LCY)");
ErrorInfo.DetailedMessage := 'Reduce order or request limit increase.';
ErrorInfo.PageNo := Page::"Customer Card";
ErrorInfo.RecordId := Customer.RecordId;
Error(ErrorInfo);
end;
end;
Use [TryFunction] only for operations that do not perform any database writes (no Insert, Modify, Delete, or codeunit runs that trigger CRUD). TryFunctions catch runtime errors and return false — they do not roll back any partial writes.
Valid use cases: parsing/conversion, external service calls, validation logic with no side effects.
// CORRECT - TryFunction for parsing/validation only (no CRUD)
[TryFunction]
local procedure TryParseAmount(RawText: Text; var ParsedAmount: Decimal)
begin
// Pure evaluation - no database writes
ParsedAmount := ParseDecimal(RawText); // throws on invalid input
end;
procedure ImportAmount(RawText: Text): Decimal
var
ParsedAmount: Decimal;
begin
if not TryParseAmount(RawText, ParsedAmount) then
Error('Invalid amount format: %1', RawText);
exit(ParsedAmount);
end;
// WRONG - TryFunction wrapping CRUD or posting operations
[TryFunction]
local procedure TryPostDocument(var SalesHeader: Record "Sales Header")
var
SalesPost: Codeunit "Sales-Post";
begin
SalesPost.Run(SalesHeader); // NOT allowed - triggers database writes
end;
Handler suffixUse XML documentation for global procedures:
/// <summary>
/// Calculates customer balance including pending orders.
/// </summary>
/// <param name="CustomerNo">The customer number</param>
/// <returns>Total balance in LCY</returns>
procedure CalculateBalance(CustomerNo: Code[20]): Decimal
npx claudepluginhub mbaic/mb-al-ai-toolkit-cc --plugin mb-al-ai-toolkitProvides behavioral guidelines to reduce common LLM coding mistakes, focusing on simplicity, surgical changes, assumption surfacing, and verifiable success criteria.
Searches, retrieves, and installs Agent Skills from prompts.chat registry using MCP tools like search_skills and get_skill. Activates for finding skills, browsing catalogs, or extending Claude.
Creates, edits, and optimizes skills for Claude Code, including drafting, evaluating with test prompts, iterating on performance, and improving skill descriptions for better triggering accuracy.