Domain 4 β€” Module 3 of 6 50%
13 of 28 overall
Domain 4: Develop and Test Code Free ⏱ ~14 min read

Chain of Command: The Modern Extension Model

Master CoC β€” extend F&O classes without modifying original code. Learn syntax, rules, overlayering vs extensions.

Chain of Command: The Modern Extension Model

Simple explanation

CoC adds links to a chain without touching the original. Your code runs before/after the original method. next() passes control forward. Overlayering (modifying originals) is blocked β€” the extension model (CoC, event handlers, delegates) is the only supported customisation path.

Core Syntax

[ExtensionOf(classStr(SalesLineType))]
final class SalesLineType_Extension
{
    public void validateWrite()
    {
        info("Before original");
        next validateWrite();
        info("After original");
    }
}

With return values

[ExtensionOf(tableStr(SalesTable))]
final class SalesTable_Extension
{
    public boolean validateField(FieldId _fieldId)
    {
        boolean isValid = next validateField(_fieldId);
        if (_fieldId == fieldNum(SalesTable, CustAccount))
        {
            CustTable ct;
            select firstOnly ct where ct.AccountNum == this.CustAccount;
            if (ct.Blocked != CustVendorBlocked::No)
            {
                isValid = false;
                error("Blocked customer");
            }
        }
        return isValid;
    }
}

πŸ—οΈ Vik: β€œEvery client project uses CoC. Zero changes to standard classes, clean upgrade path.”

Rules

CoC Rules
RuleAllowedNot Allowed
MembersPublic/protectedPrivate = compile error
Class modifierMust be finalNot abstract
SignatureExact match requiredCannot change
nextRequired β€” must be unconditionalNo next inside if/while/after return
TargetsClasses, tables, forms, data entitiesPrivate internals

Overlayering vs Extensions

Overlayering vs Extensions
Overlayering (Dead)Extensions (CoC)
ApproachModify Microsoft codeWrap without touching
UpgradesBreaks on every updateSurvives updates
ISVConflictsMultiple extensions chain
StatusBlockedOnly supported way
AccessEverythingPublic/protected

CoC on Tables and Forms

[ExtensionOf(tableStr(CustTable))]
final class CustTable_Extension
{
    public void insert()
    {
        if (!this.Name)
        {
            throw error("Customer name is required");
        }
        next insert();
        info(strFmt("Customer %1 created", this.AccountNum));
    }
}

[ExtensionOf(formDataSourceStr(SalesTable, SalesTable))]
final class SalesForm_DS_Ext
{
    public void init()
    {
        next init();
        this.query().dataSourceTable(tableNum(SalesTable))
            .addRange(fieldNum(SalesTable, SalesStatus))
            .value(queryValue(SalesStatus::Backorder));
    }
}

Note: tableStr() for tables, formDataSourceStr(Form, DS) for form data sources.

Exam tip: next must be unconditional

The runtime requires next to always be called β€” you cannot put next inside an if statement, after a return, or inside a loop. If you need to prevent the original logic from executing, throw an exception instead of using return before next. The exam tests this: a return statement before next is a compile error.

Question

CoC extension attribute?

Click or press Enter to reveal answer

Answer

[ExtensionOf(classStr(Target))]. Use tableStr/formStr/formDataSourceStr for other types.

Click to flip back

Question

What does next do?

Click or press Enter to reveal answer

Answer

Passes control to next extension or original method. Skip it = bypass everything.

Click to flip back

Question

Why must CoC classes be final?

Click or press Enter to reveal answer

Answer

Cannot be further extended β€” prevents unpredictable hierarchies.

Click to flip back

Question

CoC vs overlayering?

Click or press Enter to reveal answer

Answer

CoC wraps without modifying. Overlayering modified originals and is now blocked.

Click to flip back

Knowledge Check

CoC on validateWrite() without next. What happens?

Knowledge Check

Validation needed BEFORE insert. CoC structure?

Knowledge Check

Access private field from CoC extension?


Next up: Event Handlers & Delegates β€” the other extensibility pattern.