bcquality/custom/knowledge/integration/version-business-events-and-keep-payloads-stable.good.al
Tharanga Chandrasekara 07140e2223 Add new action skills for AL testing and documentation
- Introduced `al-test-writer` to generate AL test codeunits for production objects based on TDD principles.
- Added `al-userguide-test-writer` to create test codeunits from user guide steps, mapping actions and assertions.
- Implemented `bc-extension-test-guide` to generate a comprehensive TEST_GUIDE.md for Business Central extensions, covering various categories.
- Created `bc-webclient-runner` to automate UI testing of the Business Central web client, capturing screenshots and asserting UI states.
- Developed `page-scripting-e2e` to produce a recording plan for Page Scripting, ensuring a structured approach to browser-level testing.
2026-06-07 12:26:47 +12:00

42 lines
2 KiB
AL

// Best practice: one events codeunit per version, versioned procedure names, a minimal
// stable DTO of identifiers, validation before firing, and transient/permanent classification.
codeunit 50170 "Order Events v1"
{
// Shipped contract. Once a subscriber binds to OnOrderConfirmed_v1, this signature is FROZEN.
// Parameters are identifiers only: a subscriber calls back for detail, so no field leaks and
// no secret travels in the payload.
[ExternalBusinessEvent('OrderConfirmed', 'Order confirmed', 'Raised when a sales order is confirmed', EventCategory::Sales)]
procedure OnOrderConfirmed_v1(OrderNo: Code[20]; ExternalRef: Text[100])
begin
end;
}
codeunit 50171 "Order Event Publisher"
{
procedure Publish(SalesHeader: Record "Sales Header")
var
Events: Codeunit "Order Events v1";
begin
// Validate BEFORE firing. A header with no number cannot produce a meaningful
// notification, so this is a PERMANENT failure: fail and alert, do not publish it and
// let the platform retry an unfixable payload for 36 hours.
if SalesHeader."No." = '' then
Error('Cannot publish OrderConfirmed without a document number');
// Transient conditions (subscriber temporarily down, network blip) are NOT handled here:
// the platform's external-event delivery retries those for us. We only guard permanent ones.
Events.OnOrderConfirmed_v1(SalesHeader."No.", SalesHeader."External Document No.");
end;
}
// A breaking change does NOT edit OnOrderConfirmed_v1. It ships a NEW codeunit with a NEW
// procedure, so v1 subscribers keep receiving exactly what they bound to and new subscribers
// opt into the richer v2 shape.
codeunit 50172 "Order Events v2"
{
[ExternalBusinessEvent('OrderConfirmedV2', 'Order confirmed (v2)', 'Adds the warehouse location code', EventCategory::Sales)]
procedure OnOrderConfirmed_v2(OrderNo: Code[20]; ExternalRef: Text[100]; LocationCode: Code[10])
begin
end;
}