Exercise: Design and implement a standards-based document
In this exercise, you build an inspection-request extension that separates setup, equipment master data, an editable document, processing logic, and permanent entries. Use object IDs 70800–70899 in a Business Central online sandbox.
Classify the design
Create a short design record before you write AL code. Use the following classification as your implementation contract:
| Object | Responsibility | Lifecycle rule |
|---|---|---|
| Inspection Setup | Setup | Stores one company's number-series choices. |
| Inspection Equipment | Master | Provides reusable equipment identity and blocked state. |
| Inspection Request Header | Document header | Owns document identity, equipment, date, and status. |
| Inspection Request Line | Document line | Stores repeated checklist details for one header. |
| Inspection Entry | Ledger-style entry | Preserves processed inspection results. |
| Inspection Request Mgt. | Processing codeunit | Owns release, reopen, validation, and processing transitions. |
The exercise doesn't add a register because each request is processed as one transaction. Add a register in a later design if users must group entries from a batch and navigate by processing run.
Create setup and status objects
Create InspectionRequestStatus.Enum.al for the document states:
enum 70800 "Inspection Request Status"
{
Extensible = true;
value(0; Open)
{
Caption = 'Open';
}
value(1; Released)
{
Caption = 'Released';
}
}
Create InspectionSetup.Table.al and InspectionSetup.Page.al. The blank primary key creates one setup record per company.
table 70800 "Inspection Setup"
{
Caption = 'Inspection Setup';
DataClassification = CustomerContent;
fields
{
field(1; "Primary Key"; Code[10])
{
Caption = 'Primary Key';
DataClassification = SystemMetadata;
}
field(2; "Equipment Nos."; Code[20])
{
Caption = 'Equipment Nos.';
TableRelation = "No. Series".Code;
DataClassification = CustomerContent;
}
field(3; "Request Nos."; Code[20])
{
Caption = 'Request Nos.';
TableRelation = "No. Series".Code;
DataClassification = CustomerContent;
}
}
keys
{
key(PK; "Primary Key")
{
Clustered = true;
}
}
}
page 70800 "Inspection Setup"
{
PageType = Card;
SourceTable = "Inspection Setup";
Caption = 'Inspection Setup';
ApplicationArea = All;
UsageCategory = Administration;
InsertAllowed = false;
DeleteAllowed = false;
layout
{
area(Content)
{
group(Numbering)
{
Caption = 'Numbering';
field(EquipmentNos; Rec."Equipment Nos.")
{
ApplicationArea = All;
ToolTip = 'Specifies the number series used for equipment records.';
}
field(RequestNos; Rec."Request Nos.")
{
ApplicationArea = All;
ToolTip = 'Specifies the number series used for inspection requests.';
}
}
}
}
trigger OnOpenPage()
begin
if not Rec.Get() then begin
Rec.Init();
Rec.Insert();
end;
end;
}
Implement equipment master data
Create InspectionEquipment.Table.al. The table assigns numbers, supports useful lookups, and rejects deletion while a document or entry references the equipment.
table 70801 "Inspection Equipment"
{
Caption = 'Inspection Equipment';
DataClassification = CustomerContent;
LookupPageId = "Inspection Equipment List";
DrillDownPageId = "Inspection Equipment List";
fields
{
field(1; "No."; Code[20])
{
Caption = 'No.';
DataClassification = CustomerContent;
trigger OnValidate()
begin
if "No." <> xRec."No." then begin
InspectionSetup.Get();
NoSeries.TestManual(InspectionSetup."Equipment Nos.");
"No. Series" := '';
end;
end;
}
field(2; Description; Text[100])
{
Caption = 'Description';
DataClassification = CustomerContent;
}
field(3; Blocked; Boolean)
{
Caption = 'Blocked';
DataClassification = CustomerContent;
}
field(4; "No. Series"; Code[20])
{
Caption = 'No. Series';
Editable = false;
TableRelation = "No. Series".Code;
DataClassification = CustomerContent;
}
}
keys
{
key(PK; "No.")
{
Clustered = true;
}
key(DescriptionKey; Description)
{
}
}
fieldgroups
{
fieldgroup(DropDown; "No.", Description)
{
}
}
trigger OnInsert()
begin
if "No." = '' then begin
InspectionSetup.Get();
InspectionSetup.TestField("Equipment Nos.");
"No. Series" := InspectionSetup."Equipment Nos.";
"No." := NoSeries.GetNextNo("No. Series");
end;
end;
trigger OnDelete()
var
InspectionHeader: Record "Inspection Request Header";
InspectionEntry: Record "Inspection Entry";
begin
InspectionHeader.SetRange("Equipment No.", "No.");
if not InspectionHeader.IsEmpty() then
Error(EquipmentInRequestErr, "No.");
InspectionEntry.SetRange("Equipment No.", "No.");
if not InspectionEntry.IsEmpty() then
Error(EquipmentInEntryErr, "No.");
end;
trigger OnRename()
begin
Error(RenameErr);
end;
var
InspectionSetup: Record "Inspection Setup";
NoSeries: Codeunit "No. Series";
EquipmentInRequestErr: Label 'Equipment %1 is used by an inspection request and can''t be deleted.';
EquipmentInEntryErr: Label 'Equipment %1 is used by an inspection entry and can''t be deleted.';
RenameErr: Label 'Equipment numbers can''t be changed after the record is created.';
}
Create InspectionEquipmentPages.Page.al with a list and card page:
page 70801 "Inspection Equipment List"
{
PageType = List;
SourceTable = "Inspection Equipment";
Caption = 'Inspection Equipment';
ApplicationArea = All;
UsageCategory = Lists;
CardPageId = "Inspection Equipment Card";
Editable = false;
layout
{
area(Content)
{
repeater(Equipment)
{
field("No."; Rec."No.")
{
ApplicationArea = All;
ToolTip = 'Specifies the equipment number.';
}
field(Description; Rec.Description)
{
ApplicationArea = All;
ToolTip = 'Specifies the equipment description.';
}
field(Blocked; Rec.Blocked)
{
ApplicationArea = All;
ToolTip = 'Specifies whether new inspection requests are blocked for the equipment.';
}
}
}
}
}
page 70802 "Inspection Equipment Card"
{
PageType = Card;
SourceTable = "Inspection Equipment";
Caption = 'Inspection Equipment Card';
ApplicationArea = All;
layout
{
area(Content)
{
group(General)
{
Caption = 'General';
field("No."; Rec."No.")
{
ApplicationArea = All;
ToolTip = 'Specifies the equipment number.';
}
field(Description; Rec.Description)
{
ApplicationArea = All;
ToolTip = 'Specifies the equipment description.';
}
field(Blocked; Rec.Blocked)
{
ApplicationArea = All;
ToolTip = 'Specifies whether new inspection requests are blocked for the equipment.';
}
}
}
}
actions
{
area(Navigation)
{
action(InspectionEntries)
{
ApplicationArea = All;
Caption = 'Inspection entries';
Image = Entries;
RunObject = page "Inspection Entries";
RunPageLink = "Equipment No." = field("No.");
ToolTip = 'View processed inspection entries for the equipment.';
}
}
}
}
Build the document tables
Create InspectionRequestHeader.Table.al. The header owns numbering, equipment defaults, status, and line deletion.
table 70802 "Inspection Request Header"
{
Caption = 'Inspection Request Header';
DataClassification = CustomerContent;
LookupPageId = "Inspection Request List";
DrillDownPageId = "Inspection Request List";
fields
{
field(1; "No."; Code[20])
{
Caption = 'No.';
DataClassification = CustomerContent;
trigger OnValidate()
begin
TestStatusOpen();
if "No." <> xRec."No." then begin
InspectionSetup.Get();
NoSeries.TestManual(InspectionSetup."Request Nos.");
"No. Series" := '';
end;
end;
}
field(2; "Equipment No."; Code[20])
{
Caption = 'Equipment No.';
TableRelation = "Inspection Equipment"."No." where(Blocked = const(false));
DataClassification = CustomerContent;
trigger OnValidate()
var
InspectionEquipment: Record "Inspection Equipment";
begin
TestStatusOpen();
if "Equipment No." = '' then begin
Description := '';
exit;
end;
InspectionEquipment.Get("Equipment No.");
InspectionEquipment.TestField(Blocked, false);
Description := InspectionEquipment.Description;
end;
}
field(3; Description; Text[100])
{
Caption = 'Description';
DataClassification = CustomerContent;
trigger OnValidate()
begin
TestStatusOpen();
end;
}
field(4; "Request Date"; Date)
{
Caption = 'Request Date';
DataClassification = CustomerContent;
trigger OnValidate()
begin
TestStatusOpen();
end;
}
field(5; Status; Enum "Inspection Request Status")
{
Caption = 'Status';
Editable = false;
DataClassification = CustomerContent;
}
field(6; "No. Series"; Code[20])
{
Caption = 'No. Series';
Editable = false;
TableRelation = "No. Series".Code;
DataClassification = CustomerContent;
}
}
keys
{
key(PK; "No.")
{
Clustered = true;
}
key(EquipmentDate; "Equipment No.", "Request Date")
{
}
}
trigger OnInsert()
begin
if "No." = '' then begin
InspectionSetup.Get();
InspectionSetup.TestField("Request Nos.");
"No. Series" := InspectionSetup."Request Nos.";
"No." := NoSeries.GetNextNo("No. Series");
end;
"Request Date" := WorkDate();
end;
trigger OnDelete()
var
InspectionLine: Record "Inspection Request Line";
begin
TestStatusOpen();
InspectionLine.SetRange("Document No.", "No.");
InspectionLine.DeleteAll(false);
end;
trigger OnRename()
begin
Error(RenameErr);
end;
procedure TestStatusOpen()
begin
TestField(Status, Status::Open);
end;
var
InspectionSetup: Record "Inspection Setup";
NoSeries: Codeunit "No. Series";
RenameErr: Label 'Inspection request numbers can''t be changed after the document is created.';
}
Create InspectionRequestLine.Table.al. The line table enforces the open-document rule for every caller.
table 70803 "Inspection Request Line"
{
Caption = 'Inspection Request Line';
DataClassification = CustomerContent;
fields
{
field(1; "Document No."; Code[20])
{
Caption = 'Document No.';
TableRelation = "Inspection Request Header"."No.";
DataClassification = CustomerContent;
}
field(2; "Line No."; Integer)
{
Caption = 'Line No.';
DataClassification = SystemMetadata;
}
field(3; "Checklist Item"; Text[100])
{
Caption = 'Checklist Item';
DataClassification = CustomerContent;
}
field(4; Completed; Boolean)
{
Caption = 'Completed';
DataClassification = CustomerContent;
}
}
keys
{
key(PK; "Document No.", "Line No.")
{
Clustered = true;
}
}
trigger OnInsert()
begin
TestStatusOpen();
end;
trigger OnModify()
begin
TestStatusOpen();
end;
trigger OnDelete()
begin
TestStatusOpen();
end;
trigger OnRename()
begin
Error(RenameErr);
end;
local procedure TestStatusOpen()
var
InspectionHeader: Record "Inspection Request Header";
begin
InspectionHeader.Get("Document No.");
InspectionHeader.TestStatusOpen();
end;
var
RenameErr: Label 'Inspection request lines can''t be renamed.';
}
Add processing and history
Create InspectionEntry.Table.al and InspectionEntries.Page.al. Entries are inserted by processing and displayed as read-only history.
table 70804 "Inspection Entry"
{
Caption = 'Inspection Entry';
DataClassification = CustomerContent;
DrillDownPageId = "Inspection Entries";
fields
{
field(1; "Entry No."; Integer)
{
Caption = 'Entry No.';
AutoIncrement = true;
DataClassification = SystemMetadata;
}
field(2; "Request No."; Code[20])
{
Caption = 'Request No.';
DataClassification = CustomerContent;
}
field(3; "Equipment No."; Code[20])
{
Caption = 'Equipment No.';
TableRelation = "Inspection Equipment"."No.";
DataClassification = CustomerContent;
}
field(4; "Equipment Description"; Text[100])
{
Caption = 'Equipment Description';
DataClassification = CustomerContent;
}
field(5; "Request Date"; Date)
{
Caption = 'Request Date';
DataClassification = CustomerContent;
}
field(6; "Line No."; Integer)
{
Caption = 'Line No.';
DataClassification = SystemMetadata;
}
field(7; "Checklist Item"; Text[100])
{
Caption = 'Checklist Item';
DataClassification = CustomerContent;
}
}
keys
{
key(PK; "Entry No.")
{
Clustered = true;
}
key(EquipmentHistory; "Equipment No.", "Request Date")
{
}
}
}
page 70806 "Inspection Entries"
{
PageType = List;
SourceTable = "Inspection Entry";
Caption = 'Inspection Entries';
ApplicationArea = All;
UsageCategory = History;
Editable = false;
InsertAllowed = false;
DeleteAllowed = false;
layout
{
area(Content)
{
repeater(Entries)
{
field("Entry No."; Rec."Entry No.")
{
ApplicationArea = All;
ToolTip = 'Specifies the sequential entry number.';
}
field("Request No."; Rec."Request No.")
{
ApplicationArea = All;
ToolTip = 'Specifies the inspection request that created the entry.';
}
field("Equipment No."; Rec."Equipment No.")
{
ApplicationArea = All;
ToolTip = 'Specifies the inspected equipment.';
}
field("Equipment Description"; Rec."Equipment Description")
{
ApplicationArea = All;
ToolTip = 'Specifies the equipment description captured during processing.';
}
field("Request Date"; Rec."Request Date")
{
ApplicationArea = All;
ToolTip = 'Specifies the date from the inspection request.';
}
field("Checklist Item"; Rec."Checklist Item")
{
ApplicationArea = All;
ToolTip = 'Specifies the completed checklist item.';
}
}
}
}
}
Create InspectionRequestMgt.Codeunit.al. Processing runs in one transaction, so failed validation doesn't leave partial entries.
codeunit 70800 "Inspection Request Mgt."
{
procedure Release(var InspectionHeader: Record "Inspection Request Header")
var
InspectionLine: Record "Inspection Request Line";
begin
InspectionHeader.TestStatusOpen();
InspectionHeader.TestField("Equipment No.");
InspectionHeader.TestField("Request Date");
InspectionLine.SetRange("Document No.", InspectionHeader."No.");
if not InspectionLine.FindSet() then
Error(NoLinesErr);
repeat
InspectionLine.TestField("Checklist Item");
until InspectionLine.Next() = 0;
InspectionHeader.Status := InspectionHeader.Status::Released;
InspectionHeader.Modify(true);
end;
procedure Reopen(var InspectionHeader: Record "Inspection Request Header")
begin
InspectionHeader.TestField(Status, InspectionHeader.Status::Released);
InspectionHeader.Status := InspectionHeader.Status::Open;
InspectionHeader.Modify(true);
end;
procedure Process(var InspectionHeader: Record "Inspection Request Header")
var
InspectionLine: Record "Inspection Request Line";
InspectionEntry: Record "Inspection Entry";
begin
InspectionHeader.TestField(Status, InspectionHeader.Status::Released);
InspectionLine.SetRange("Document No.", InspectionHeader."No.");
if not InspectionLine.FindSet() then
Error(NoLinesErr);
repeat
InspectionLine.TestField("Checklist Item");
InspectionLine.TestField(Completed, true);
InspectionEntry.Init();
InspectionEntry."Request No." := InspectionHeader."No.";
InspectionEntry."Equipment No." := InspectionHeader."Equipment No.";
InspectionEntry."Equipment Description" := InspectionHeader.Description;
InspectionEntry."Request Date" := InspectionHeader."Request Date";
InspectionEntry."Line No." := InspectionLine."Line No.";
InspectionEntry."Checklist Item" := InspectionLine."Checklist Item";
InspectionEntry.Insert(true);
until InspectionLine.Next() = 0;
InspectionLine.DeleteAll(false);
InspectionHeader.Delete(false);
end;
var
NoLinesErr: Label 'Add at least one inspection request line before you continue.';
}
Create the document pages
Create InspectionRequestPages.Page.al with the subpage, list, and document page:
page 70803 "Inspection Request Subpage"
{
PageType = ListPart;
SourceTable = "Inspection Request Line";
Caption = 'Lines';
ApplicationArea = All;
AutoSplitKey = true;
DelayedInsert = true;
layout
{
area(Content)
{
repeater(Lines)
{
field("Checklist Item"; Rec."Checklist Item")
{
ApplicationArea = All;
ToolTip = 'Specifies the inspection task that must be completed.';
}
field(Completed; Rec.Completed)
{
ApplicationArea = All;
ToolTip = 'Specifies whether the inspection task is complete.';
}
}
}
}
}
page 70804 "Inspection Request List"
{
PageType = List;
SourceTable = "Inspection Request Header";
Caption = 'Inspection Requests';
ApplicationArea = All;
UsageCategory = Lists;
CardPageId = "Inspection Request";
Editable = false;
layout
{
area(Content)
{
repeater(Requests)
{
field("No."; Rec."No.")
{
ApplicationArea = All;
ToolTip = 'Specifies the inspection request number.';
}
field("Equipment No."; Rec."Equipment No.")
{
ApplicationArea = All;
ToolTip = 'Specifies the equipment for the inspection.';
}
field(Description; Rec.Description)
{
ApplicationArea = All;
ToolTip = 'Specifies the equipment description.';
}
field("Request Date"; Rec."Request Date")
{
ApplicationArea = All;
ToolTip = 'Specifies the inspection request date.';
}
field(Status; Rec.Status)
{
ApplicationArea = All;
ToolTip = 'Specifies whether the request is open or released.';
}
}
}
}
}
page 70805 "Inspection Request"
{
PageType = Document;
SourceTable = "Inspection Request Header";
Caption = 'Inspection Request';
ApplicationArea = All;
RefreshOnActivate = true;
layout
{
area(Content)
{
group(General)
{
Caption = 'General';
Editable = IsOpen;
field("No."; Rec."No.")
{
ApplicationArea = All;
ToolTip = 'Specifies the inspection request number.';
}
field("Equipment No."; Rec."Equipment No.")
{
ApplicationArea = All;
ToolTip = 'Specifies the equipment for the inspection.';
}
field(Description; Rec.Description)
{
ApplicationArea = All;
ToolTip = 'Specifies the equipment description copied to inspection history.';
}
field("Request Date"; Rec."Request Date")
{
ApplicationArea = All;
ToolTip = 'Specifies the inspection request date.';
}
field(Status; Rec.Status)
{
ApplicationArea = All;
ToolTip = 'Specifies whether the request is open or released.';
}
}
part(Lines; "Inspection Request Subpage")
{
ApplicationArea = All;
SubPageLink = "Document No." = field("No.");
UpdatePropagation = Both;
Editable = IsOpen;
}
}
}
actions
{
area(Processing)
{
action(Release)
{
ApplicationArea = All;
Caption = 'Release';
Image = ReleaseDoc;
Enabled = IsOpen;
ToolTip = 'Validate the inspection request and prevent further editing.';
trigger OnAction()
begin
InspectionRequestMgt.Release(Rec);
SetControlState();
CurrPage.Update(false);
end;
}
action(Reopen)
{
ApplicationArea = All;
Caption = 'Reopen';
Image = ReOpen;
Enabled = IsReleased;
ToolTip = 'Return the inspection request to the open state for editing.';
trigger OnAction()
begin
InspectionRequestMgt.Reopen(Rec);
SetControlState();
CurrPage.Update(false);
end;
}
action(Process)
{
ApplicationArea = All;
Caption = 'Process';
Image = Post;
Enabled = IsReleased;
ToolTip = 'Create inspection entries and remove the processed request.';
trigger OnAction()
begin
InspectionRequestMgt.Process(Rec);
CurrPage.Close();
end;
}
}
}
trigger OnAfterGetCurrRecord()
begin
SetControlState();
end;
var
InspectionRequestMgt: Codeunit "Inspection Request Mgt.";
IsOpen: Boolean;
IsReleased: Boolean;
local procedure SetControlState()
begin
IsOpen := Rec.Status = Rec.Status::Open;
IsReleased := Rec.Status = Rec.Status::Released;
end;
}
Publish and validate the flow
Publish the extension, and then complete these setup and master-data checks:
- Create number series named
INSP-EQPandINSP-REQ, with starting numbersEQP0001andREQ0001. - Open Inspection Setup, and assign both number series.
- Create an equipment record, and confirm that Business Central assigns its number.
- Confirm that the equipment lookup displays its number and description.
- Create an inspection request, select the equipment, and confirm that the description defaults.
Complete these document and history checks:
- Add two checklist lines, and confirm that line numbers remain unique within the request.
- Release the request, and confirm that the header and lines aren't editable.
- Reopen the request, select Completed on both lines, and release it again.
- Process the request, and confirm that the source document is removed and two inspection entries exist.
- Try to delete the equipment, and confirm that the historical reference prevents deletion.
- Verify that the entries retain the request number, equipment description, date, line number, and checklist text.
Record the result of each check and identify the object that owns the behavior. The setup table owns number-series policy, the master table owns protected deletion, the document tables own editable state, the management codeunit owns transitions, and the entry table owns history.