MSBA-348 · Lesson 5 of 12 · 18 min

Domain review: extensions

▶ Video coming soon A video version of this lesson is on the way.

Extensions are the heart of modern finance and operations development, and in the new outline they are spread across two domains. User interface elements (forms, menus, labels, custom controls, style sheets and operational workspaces) sit in Design and develop AOT elements. Classes, Chain of Command, event handlers, delegates, the frameworks and testing sit in Develop and test code. This lesson reviews them together, because the exam's scenarios do: a requirement to change a standard purchase order usually needs a table extension, a form extension, a Chain of Command class and a test.

Desmond used the foundry inspection certificate feature from Extending Finance and Operations Apps as the running example. Prudence knew it well; she had written most of it. "Then explain every element of it," he said, "and for each one, tell me what the exam's wrong answers would be."

Forms and form extensions

Forms are built on form patterns: Details Master, Simple List, Simple List and Details, List Page, Table of Contents, Dialog, Workspace and others, each with sub-patterns for tabs and groups. The pattern decides the arrangement of controls and is checked by the designer; a form that does not match its pattern shows a pattern error. The pump warranty form used Simple List and Details because users scan a list of serial numbers and edit one record at a time.

A form extension can add controls, data sources, field groups and event handlers, change some properties and reorder controls. It cannot remove standard controls or change their data binding. Behaviour on form methods, data sources and controls is changed with Chain of Command on the form, data source, data field or control (using formStr, formDataSourceStr, formDataFieldStr and formControlStr in the ExtensionOf attribute) or with form event handlers such as OnInitialized, OnModified and OnClicked. The PurchTable.CRCustom extension added the inspection field group to the purchase line details and a button for waiver requests.

Menu items are the entry points to forms (display), reports (output) and classes (action). They carry the security link: a privilege grants access to a menu item, not to a form directly. Menus organize menu items for navigation; a menu extension adds items to a standard module menu. Cobalt Ridge added Pump warranties under Inventory management. Exam questions check that you use the right kind of menu item: a report is an output item, a batch job or service operation is an action item, and a form is a display item.

Label files hold user-visible text in each language. A label is referenced as @LabelFileId:LabelId, such as @CRCustom:WarrantyMonths, and labels are created in the label editor for each language, with a translation service available for draft translations. Any property that users see, such as Label, HelpText or Caption, should use a label; a literal string raises a best practice warning. Cobalt Ridge's label file had four languages, and its only UAT defect in the inspection project was a French label for heat number.

Custom controls, style sheets and operational workspaces

The outline adds create custom controls and style sheets. Most requirements are met by standard controls. When none fits, for example a visual pump curve chart on a form, a developer can build an extensible control: an X++ build class that defines design-time properties, an X++ runtime class that holds the control's state and server logic, and HTML, JavaScript and CSS resources that render it in the browser. The resources are added to the model as resource elements. Style sheets in this context are those CSS resources; they style the control, not the whole application. The exam is likely to ask when a custom control is justified, which parts make one, or where its resources live, rather than to show JavaScript.

Operational workspaces are forms built on the Workspace pattern. A workspace gives a role one page with tiles that show counts or KPIs from queries, tabbed lists of records that need attention, links to related pages and, optionally, embedded Power BI content. Creating a workspace means creating the form with the pattern, tiles that point to menu items and queries, list parts and a menu item; extending one means adding tiles, lists or links to a standard workspace through a form extension. In the extension clinics Prudence added a casting certificates tile, counting purchase lines awaiting certificates, to the standard purchase workspace.

Classes and object-oriented code

The object-oriented objective lists creating and extending classes, adding methods, adding attributes or modifiers, implementing variable scoping, inheritance and abstraction, attribute classes, Chain of Command, and event handler classes and delegates. Most of it is the X++ you have written since the fundamentals course: classes with public, protected, private and internal access; static and instance methods; final classes and methods; abstract classes whose abstract methods subclasses must implement; interfaces; and constructors through new and the construct pattern.

Attribute classes are classes that extend SysAttribute. They let you decorate classes and methods with metadata that other code reads at run time. The SysExtension framework, the batch retry interface, data contracts and the event handler attributes are all built on them. An exam question might show a custom attribute class with a constructor parameter and ask how a factory finds the right subclass for an enum value: through SysExtensionAppClassFactory and the attribute on each subclass.

Variable scoping in X++ follows block rules in modern code: a variable declared inside a block, including the loop body, is visible only within it, and variables can be declared where they are first used. Class-level variables are instance members, and their access modifier controls visibility to subclasses and extensions. Questions on scoping often show a variable used outside the block where it was declared and ask whether the code compiles.

Chain of Command

Chain of Command, or CoC, is how you wrap a method of a standard class, table, form, data source or control. You create a final class decorated with the ExtensionOf attribute that names the target, declare a method with the same signature, and call next to run the next method in the chain, which eventually runs the original. Code before next runs before the standard logic; code after next runs after it and can read or change the return value.

A Chain of Command wrapper on a table method. next is called unconditionally and the result is combined with the extra rule.
[ExtensionOf(tableStr(PurchLine))]
final class CRPurchLine_Extension
{
    public boolean validateWrite()
    {
        boolean ok = next validateWrite();

        if (ok && this.CRInspectionRequired == NoYes::Yes && !this.CRHeatNumber)
        {
            ok = checkFailed("@CRCustom:HeatNumberRequired");
        }
        return ok;
    }
}

The rules the exam checks are precise. The extension class must be final and its name should end in _Extension. The wrapper must call next, and must call it unconditionally at the first level of the method, not inside an if or a loop, unless the target method is marked with the Replaceable attribute, in which case the wrapper may skip next. Default parameter values are not repeated in the wrapper's signature. Protected and public methods can be wrapped; private methods cannot. Methods marked Hookable false or Wrappable false cannot be wrapped. Wrappers can access protected members of the class they extend. When several models wrap the same method, the order in which wrappers run is not guaranteed, so a wrapper must not depend on another model's wrapper.

Event handlers and delegates

Event handlers subscribe to events that the platform raises: data events on tables (such as onInserting, onInserted, onValidatedWrite, onDeleted), form and control events (OnInitialized, OnClicked, OnModified) and pre and post events on methods. A handler is a static method in a class, decorated with an attribute that names the event, such as DataEventHandler. For new code, CoC is usually preferred to pre and post handlers on methods because it is simpler and has access to protected members; data events remain useful for reacting to every insert or delete of a table regardless of which method caused it.

A delegate is a method with an empty body that a class calls to let subscribers add logic at a specific point. Subscribers are static methods decorated with SubscribesTo, naming the class and delegateStr of the delegate. Delegates are how standard code offers a hook with a defined contract, often passing an EventHandlerResult object so that a subscriber can return a value. In the extension clinics, the extensibility request Desmond filed asked Microsoft for exactly this: a delegate in the receipt check.

Choosing an extension technique for business logic.
TechniqueUse it whenWatch out for
Chain of CommandChanging or adding to a method of a class, table, form or data sourceCall next unconditionally; private methods cannot be wrapped
Data event handlerReacting to every insert, update or delete of a tableRuns per record; set-based operations may fall back to row by row
Form event handlerReacting to form or control eventsUse the event arguments to reach the form or control
Delegate subscriptionThe standard code exposes a delegate for this pointReturn values through EventHandlerResult
Pre and post method handlersLegacy code or rare casesCoC is preferred for new code
A vertical chain. A call to PurchLine.validateWrite enters the Cobalt Ridge wrapper, which runs code before next, calls next, which enters another model's wrapper and then the standard method. Control returns up the chain, and each wrapper can run code after next and change the return value. A note says the order between models is not guaranteed.
Chain of Command wrappers run around the standard method. Each must call next.

Framework functionality

The third objective group lists five frameworks. The SysOperation framework separates a data contract (parameters, with DataContract and DataMember attributes), a controller (how and where it runs, synchronous, asynchronous or in batch) and a service (the logic), with an optional UI builder for the dialog. It replaces the older RunBase pattern for new jobs. The batch framework runs jobs on the batch server: batch jobs with tasks, dependencies, recurrence, batch groups and priorities. A class designed for batch should be safe to retry; implementing the BatchRetryable interface tells the framework it may retry the job after a transient failure.

The SysExtensionSerializer framework is often confused with the SysExtension framework, which is a factory based on attributes. SysExtensionSerializer supports the extension table pattern: extra fields for a base table are stored in a separate table with a one-to-one relation, and two maps, SysExtensionSerializerMap on the base table and SysExtensionSerializerExtensionMap on the extension table, let the framework pack, save and load the extension record together with the base record. You will meet it in localization tables. The query objects skill covers building queries in code with Query, QueryBuildDataSource, QueryBuildRange and QueryRun, including SysQuery::value and queryValue to build safe range strings. The workflow framework skill covers workflow categories, types, approval and task elements, the document class that exposes fields to conditions, event handlers for submit, approve and reject, and the form properties that make a form workflow-enabled.

A query built in code: warranties ending in the next 30 days, sorted by end date. SysQuery and queryValue build safe range strings.
Query                 q   = new Query();
QueryBuildDataSource  qbds = q.addDataSource(tableNum(CRPumpWarrantyTable));

qbds.addRange(fieldNum(CRPumpWarrantyTable, Status))
    .value(queryValue(CRWarrantyStatus::Active));
qbds.addRange(fieldNum(CRPumpWarrantyTable, EndDate))
    .value(SysQuery::range(today(), today() + 30));
qbds.addSortField(fieldNum(CRPumpWarrantyTable, EndDate));

QueryRun qr = new QueryRun(q);
while (qr.next())
{
    CRPumpWarrantyTable w = qr.get(tableNum(CRPumpWarrantyTable));
    // notify the customer
}

Testing

The last objective group is perform testing: create unit tests with the SysTest framework and Task recorder, and run them in Test Explorer. A test class extends SysTestCase and its test methods carry the SysTestMethod attribute; assertions such as assertEquals, assertTrue and assertNotNull compare outcomes. Tests live in a separate test model, such as CobaltRidgeCustomTests, so that they are not deployed to production. Task recorder recordings of business processes can be imported into Visual Studio to generate test code, and the Acceptance Test Library helps create test data with readable code. Test Explorer in Visual Studio discovers, runs and reports the tests, and a pipeline can run them on every pull request.

Regression suite automation, or RSAT, also runs Task recorder recordings as tests from Azure DevOps test plans, but Microsoft has marked it for deprecation and it is not supported after May 15, 2027. The outline's testing objective names SysTest, Task recorder and Test Explorer, not RSAT, and Cobalt Ridge has a replacement decision on its plan for the first quarter of 2027.

Choosing the technique in a scenario

Extension questions usually describe what must happen and when, and the timing words choose the technique. "Before the record is saved" points to validateWrite through Chain of Command or the ValidatedWrite data event. "After every insert, whichever process inserts" points to an Inserted data event. "When the user clicks the button" points to a form control's clicked method or OnClicked event. "At this documented point in the posting" points to a delegate, if the standard code provides one, or to an extensibility request if it does not. "For every company except one" points to a condition on curExt inside whatever technique fits.

Prudence also learned to watch for questions about where code lives. Chain of Command for a table goes in a class, not in the table extension element. Event handler methods live in a class and are static. Labels live in label files, not in code. Tests live in a test model. Resources for a custom control are resource elements in the model. A correct technique placed in the wrong element is a wrong answer, and the exam includes such options deliberately.

Common mistakes

  • MistakeCalling next inside an if statement in a wrapper.

    InsteadCall next unconditionally, unless the method is marked Replaceable.

  • MistakeGranting a privilege directly on a form.

    InsteadPrivileges grant access to menu items, which open forms, reports and classes.

  • MistakeConfusing SysExtension with SysExtensionSerializer.

    InsteadSysExtension is an attribute-based factory; SysExtensionSerializer manages extension tables through two maps.

  • MistakePutting tests in the same model as production code.

    InsteadKeep tests in a separate test model that is not deployed to production.

  • MistakeBuilding a custom control for a requirement a standard control meets.

    InsteadUse a standard control first; custom controls need a build class, a runtime class and resources to maintain.

Summary and key terms

  • UI elements: forms follow patterns; form extensions add but do not remove; menu items connect navigation and security; labels hold all user-visible text.
  • Custom controls need a build class, a runtime class and HTML, JavaScript and CSS resources; operational workspaces use the Workspace pattern with tiles, lists and links.
  • Chain of Command wraps public and protected methods in a final _Extension class and must call next unconditionally unless the method is Replaceable.
  • Event handlers react to data, form and method events; delegates are hooks with empty bodies that subscribers attach to.
  • Frameworks: SysOperation (contract, controller, service), batch, SysExtensionSerializer extension tables, query objects and workflow.
  • Testing: SysTest classes in a test model, Task recorder-generated tests and Test Explorer.
Chain of Command
Wrapping a method in an extension class that calls next to run the original.
Delegate
An empty-bodied method that subscribers can attach logic to through SubscribesTo.
Form pattern
A predefined layout that a form and its controls must follow.
Operational workspace
A role-focused form built on the Workspace pattern, with tiles, lists and links.
SysOperation framework
The contract, controller and service pattern for jobs that run interactively or in batch.
SysTestCase
The base class for unit tests run in Test Explorer.

Practice problems

Work each problem on paper first, then reveal the answer to check.

  1. Which kind of menu item runs a SysOperation batch job?

    Show answer

    An action menu item.

  2. Can a wrapper skip next?

    Show answer

    Only if the wrapped method is marked Replaceable.

  3. Which two maps does the SysExtensionSerializer framework use?

    Show answer

    SysExtensionSerializerMap and SysExtensionSerializerExtensionMap.

Lesson quiz · 5 questions

Score 60% or more to complete this lesson.

Take the quiz