π― Reproducible Example: Customer Loyalty Points¶
β Validated: 24/24 tests passed | Time: 2 hours | Objects: 10 AL + 63 tests
This document guides you step-by-step to reproduce the complete loyalty points system example from scratch.
π Prerequisites¶
- β VS Code with AL Language extension
- β GitHub Copilot active
- β AL Development Collection installed (v2.11.0+)
- β AL project initialized or BC sandbox available
- β±οΈ Estimated time: 2 hours
π Complete Step-by-Step Guide¶
Step 0: Installation Verification (2 min)¶
# Verify agents are available
ls .github/agents/
# You should see:
# - al-architect.agent.md
# - al-conductor.agent.md
# - al-debugger.agent.md
# - al-developer.agent.md
# - al-tester.agent.md
# - al-api.agent.md
# - al-copilot.agent.md
If you don't see them:
# Reinstall
npm install github:javiarmesto/AL-Development-Collection-for-GitHub-Copilot
npx al-collection install
# Reload VS Code
Ctrl+Shift+P β "Developer: Reload Window"
Step 1: Design with al-architect (20 min)¶
sequenceDiagram
participant User
participant Architect as ποΈ al-architect
participant Docs as π .github/plans/
User->>Architect: Use al-architect mode<br/>(describe requirements)
activate Architect
Architect->>Architect: Analyze requirements
Architect->>Architect: Design data model
Architect->>Architect: Plan integration points
Architect->>Architect: Design UI components
Architect->>Docs: Generate architecture.md
Architect->>User: Complete architecture<br/>(tables, events, UI, tests)
deactivate Architect
User->>User: β
Verify design checkpoint Open GitHub Copilot Chat (Ctrl+Alt+I or Cmd+Alt+I)
Copy and paste exactly:
Use al-architect mode
Design a customer loyalty points system with these requirements:
MAIN FUNCTIONALITY:
- Customers automatically earn points when sales invoices are posted
- Earning rate: 1 point per 1% of sales amount (example: $1000 = 10 points)
- Points can be redeemed for discounts on future purchases
- Display points balance on customer card
- Record all point transactions (earning and redemption)
BUSINESS RULES:
- Calculation: 1 point = 1% of total sales amount
- Minimum redemption: 100 points
- Points do NOT expire
- Complete audit trail of all transactions
- Points only earned on posted sales invoices (not on unposted orders)
β³ Wait 2-3 minutes while al-architect analyzes and designs.
Expected result (save this for verification):
π COMPLETE ARCHITECTURE
ποΈ DATA MODEL:
1. Table 50100 "Loyalty Point Entry"
- Entry No. (Integer, PK, AutoIncrement)
- Customer No. (Code[20], TableRelation Customer)
- Points (Decimal)
- Transaction Type (Enum: Earned, Redeemed)
- Sales Document No. (Code[20])
- Transaction Date (Date)
- Description (Text[100])
2. TableExtension 50100 "Customer Ext" extends Customer
- "Loyalty Points Balance" (Decimal, FlowField SUM)
- "Loyalty Points Enabled" (Boolean)
π INTEGRATION (Event-Driven):
- EventSubscriber: OnAfterPostSalesInvoice
β Codeunit 50101 "Sales Event Subscriber"
β Calls LoyaltyManagement.AddPoints()
- Codeunit 50100 "Loyalty Management"
β AddPoints(CustomerNo, Amount)
β RedeemPoints(CustomerNo, Points)
β CalcPointsFromAmount(Amount): Decimal
β GetBalance(CustomerNo): Decimal
π UI COMPONENTS:
1. PageExtension 50100 "Customer Card Ext" extends "Customer Card"
- Adds field "Loyalty Points Balance" (Editable=false)
- Adds action "View Loyalty History"
2. Page 50100 "Loyalty Point Entries"
- SourceTable: "Loyalty Point Entry"
- PageType: List
- Filters by Customer, Date Range, Transaction Type
- DrillDown from Customer Card
π§ͺ TESTING STRATEGY:
- Test: InsertLoyaltyPointEntry
- Test: CalculatePointsFromAmount
- Test: AddPointsFromSalesInvoice
- Test: FlowFieldCalculation
- Test: RedeemPoints_Success
- Test: RedeemPoints_InsufficientBalance
- Test: RedeemPoints_BelowMinimum
β Checkpoint 1: Verify the design includes: - [ ] Loyalty Point Entry table with all fields - [ ] Customer extension with FlowField - [ ] Event subscriber on OnAfterPostSalesInvoice - [ ] Management codeunit with AddPoints/RedeemPoints - [ ] UI: Customer Card extension + History page - [ ] Testing plan with specific cases
π Generated documentation: .github/plans/architecture.md
Step 2: TDD Implementation with al-conductor (90 min)¶
In the same Copilot Chat:
Use al-conductor mode
Implement the loyalty points system designed by al-architect with strict TDD.
Implementation requirements:
- Follow RED β GREEN β REFACTOR cycle in each phase
- Generate tests BEFORE implementation code
- Use AL-Go structure (App/ and Test/ separated)
- Document each phase in .github/plans/
- Automatic code review with AL Code Review Subagent
β³ Automatic process (90 minutes):
graph TB
Start([π€ User: Use al-conductor mode]) --> Planning[π Planning Phase<br/>AL Planning Subagent<br/>5 min]
Planning --> Plan[π 7-Phase Implementation Plan]
Plan --> Phase1[π΄ Phase 1: Core Table]
Phase1 --> Red1[β RED: Write failing test]
Red1 --> Green1[β
GREEN: Minimal code to pass]
Green1 --> Refactor1[β»οΈ REFACTOR: Optimize & review]
Refactor1 --> Phase2[π΄ Phase 2-7: Repeat TDD Cycle]
Phase2 --> Objects[π¦ 10 AL Objects<br/>63 Tests<br/>100% Coverage]
Objects --> Review[β
AL Code Review Subagent<br/>Quality Gates]
Review --> Pass{All tests<br/>passing?}
Pass -->|β
Yes| Docs[π Auto-generate docs<br/>.github/plans/]
Pass -->|β No| Red1
Docs --> Complete([π Ready for Deployment])
style Start fill:#e1f5ff
style Planning fill:#fff4e1
style Red1 fill:#ffe1e1
style Green1 fill:#e1ffe1
style Refactor1 fill:#f0e1ff
style Complete fill:#e1ffe1
style Pass fill:#fff4e1 π Planning Phase (5 min)¶
AL Planning Subagent analyzes:
- Project structure
- Available BC objects
- Dependencies
Proposes 7 phases:
1. Loyalty Point Entry Table
2. Customer Extension
3. Loyalty Management Codeunit
4. Event Subscriber
5. Redemption Logic
6. Customer Card Extension
7. Loyalty Entries Page
π΄ Phase 1: Core Table (15 min)¶
RED (5 min) - AL Implementation Subagent:
// Test/LoyaltyTests.Codeunit.al
[Test]
procedure TestInsertLoyaltyPointEntry()
var
LoyaltyPointEntry: Record "Loyalty Point Entry";
begin
// [GIVEN] Empty table
LoyaltyPointEntry.DeleteAll();
// [WHEN] Insert entry
LoyaltyPointEntry.Init();
LoyaltyPointEntry."Entry No." := 1;
LoyaltyPointEntry."Customer No." := 'CUST001';
LoyaltyPointEntry.Points := 10;
LoyaltyPointEntry.Insert(true);
// [THEN] Entry exists
Assert.AreEqual(1, LoyaltyPointEntry.Count, 'Entry count');
end;
GREEN (7 min) - AL Implementation Subagent:
// App/Tables/LoyaltyPointEntry.Table.al
table 50100 "Loyalty Point Entry"
{
DataClassification = CustomerContent;
Caption = 'Loyalty Point Entry';
fields
{
field(1; "Entry No."; Integer)
{
AutoIncrement = true;
Caption = 'Entry No.';
}
field(2; "Customer No."; Code[20])
{
TableRelation = Customer."No.";
Caption = 'Customer No.';
}
field(3; Points; Decimal)
{
Caption = 'Points';
}
// ... more fields
}
keys
{
key(PK; "Entry No.")
{
Clustered = true;
}
}
}
REFACTOR (3 min) - AL Code Review Subagent validates: - β Naming conventions OK - β DataClassification correct - β Indexes optimized - β οΈ Add Transaction Type enum - β οΈ Add Points > 0 validation
Apply refactorings β Optimized code
π΄ Phase 2-7: Complete TDD Cycle (75 min)¶
Each phase follows: 1. RED: Failing test (AL Implementation Subagent) 2. GREEN: Minimal passing code (AL Implementation Subagent) 3. REFACTOR: Review and optimization (AL Code Review Subagent)
Objects generated progressively: - β Loyalty Point Entry Table - β Transaction Type Enum - β Customer Extension (FlowField) - β Loyalty Management Codeunit - β Sales Event Subscriber - β Customer Card Extension - β Loyalty Entries Page - β Permission Set
Tests generated automatically (63 tests):
β
Table Tests (8)
β
Calculation Tests (12)
β
Event Integration Tests (15)
β
FlowField Tests (8)
β
Redemption Tests (12)
β
UI Tests (8)
Step 3: Verification (5 min)¶
Expected result:
Building project...
β
Build succeeded (0 errors, 0 warnings)
Running tests...
β
63/63 tests passed (100%)
Coverage:
- Tables: 100%
- Codeunits: 100%
- Event Subscribers: 100%
- Extensions: 100%
Step 4: Permissions and Deployment (5 min)¶
β Final Checklist¶
Verify you have:
Generated code (App/): - [ ] Tables/LoyaltyPointEntry.Table.al - [ ] Enums/TransactionType.Enum.al - [ ] TableExtensions/CustomerExt.TableExtension.al - [ ] Codeunits/LoyaltyManagement.Codeunit.al - [ ] Codeunits/SalesEventSubscriber.Codeunit.al - [ ] PageExtensions/CustomerCardExt.PageExtension.al - [ ] Pages/LoyaltyPointEntries.Page.al - [ ] Permissions/LoyaltySystem.PermissionSet.al
Generated tests (Test/): - [ ] LoyaltyTests.Codeunit.al (63 test functions)
Generated documentation (.github/plans/): - [ ] architecture.md (al-architect design) - [ ] implementation-plan.md (al-conductor phases) - [ ] test-results.md (test results) - [ ] review-notes.md (AL Code Review Subagent feedback)
Metrics: - [ ] 10 AL objects created - [ ] 63 tests with 100% passing - [ ] 0 compilation errors - [ ] 0 critical warnings - [ ] Total time: ~2 hours
π§ͺ Manual Testing in BC¶
- Open Business Central
- Go to Customer Card (page 21)
- Verify new field: "Loyalty Points Balance"
- Create Sales Invoice: $1000
- Post Invoice
- Verify: Customer now has 10 points
- Open "View Loyalty History"
- Verify entry: Transaction Type = Earned, Points = 10
π What You've Learned¶
mindmap
root((Customer Loyalty<br/>Points System))
Architecture
al-architect design
Event-driven pattern
No base modifications
FlowField optimization
TDD Workflow
RED: Failing tests first
GREEN: Minimal code
REFACTOR: Optimize
100% test coverage
AL Orchestra
al-conductor orchestration
AL Planning Subagent research
AL Implementation Subagent coding
AL Code Review Subagent quality
Documentation
Auto-generated plans
Architecture docs
Test results
Review notes
Production Ready
10 AL objects
63 passing tests
Permission sets
2 hours total time β
Architectural design with al-architect before code
β
Automatic TDD with al-conductor (RED β GREEN β REFACTOR)
β
Event-driven BC without modifying base objects
β
Optimized FlowFields for aggregate calculations
β
Automatic code review with AL Code Review Subagent
β
Automatic documentation in .github/plans/
β
Comprehensive tests 100% coverage
π Troubleshooting¶
Error: "al-architect mode not found"¶
# Reinstall the collection
npm install github:javiarmesto/AL-Development-Collection-for-GitHub-Copilot --force
npx al-collection install
# Reload VS Code
Tests fail after implementation¶
Use al-debugger mode
The loyalty points tests are failing with error:
[describe the specific error you see]
Build errors¶
Field not visible on Customer Card¶
- Verify the extension was compiled
- Reload the page in BC (Ctrl+F5)
- Verify user permissions
π Next Steps¶
Now that you master the complete flow:
- Adapt the example to your specific needs
- Add features (e.g.: point expiration, VIP levels)
- Integrate with other modules (e.g.: double points on promotions)
- Share your experience on GitHub Discussions
π‘ Productivity Tips¶
- Save the architect prompt β Reuse for similar features
- Document decisions β al-conductor generates docs automatically
- Review the tests β They are excellent usage examples
- Use the reviews β AL Code Review Subagent teaches best practices
- Iterate quickly β TDD enables confident changes
Last updated: 2026-02-06
Version: 2.11.0
Validation: β
24/24 checks passed
Average time: 2 hours
Difficulty: π‘ MEDIUM