MSBA-341 · Lesson 1 of 12 · 19 min

The extension model

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

When the warranty module went live in the CONFIG sandbox, Prudence thought the hard part of finance and operations development was behind her. Desmond let her enjoy it for a day and then opened the next request in the backlog. Marisol Teixeira-Bond, the senior buyer at the Hamilton plant, wanted purchase lines for castings to record whether a foundry inspection certificate was required and which heat of metal each casting came from. Two failed inspections at Ferrolux Castings had put that supplier on hold, and Marisol never wanted to discover a bad casting on the assembly floor again. Every one of those requirements touched standard objects that Microsoft owns: the purchase order header, the purchase line, the receipt posting and the buyer's role. The second series of clinics was about changing what those objects do without changing them.

Why customers can no longer edit standard code

Earlier versions of the product, up to Dynamics AX 2012, let partners change Microsoft's source directly. The technique was called overlayering. A customer's layer held a modified copy of a standard method, form or table, and at run time the highest layer won. It was flexible and fast to build, and it was ruinous to maintain. Every time Microsoft shipped a fix or a new version, someone had to compare the customer's copy with Microsoft's new copy and merge the two by hand. Large customers had hundreds of overlayered objects and spent months on each upgrade, so many stayed on old versions for years.

When Microsoft moved finance and operations apps to a cloud service with frequent updates, overlayering had to go. Microsoft first introduced extensions alongside overlayering, then sealed its own models so that no one else could overlayer them. Application Platform and Application Foundation were sealed first, and Application Suite followed in 2019, which completed the change. Today every model that Microsoft ships is sealed, and the only supported way to change standard behaviour is to build an extension in a model of your own.

Two panels. On the left, labelled before 2017 overlayering, a red box shows the customer copy of a standard method sitting on top of the hidden standard method, with a note that every update requires merging and retesting the edited copy. On the right, labelled today extensions, a blue box shows the sealed standard model, and two green and teal boxes below it, an extension in CobaltRidgeCustom and an extension in an ISV model, point up to it. A note says updates replace the standard model and extensions recompile and keep working.
Overlayering edited copies of Microsoft code. Extensions sit beside sealed standard models.

What an extension is

An extension is an element in your own model that adds to, or changes a permitted property of, an element in another model. The original element is untouched. When the packages are compiled, the compiler and the runtime combine the original and all of its extensions into one effective object. A table extension adds fields to the table, a form extension adds controls to the form, and a class extension adds methods to the class or wraps existing ones. Because the standard model never changes, Microsoft can replace it with a new version and your extensions are simply recompiled against it.

Extensions are additive by design. You can add new things freely and change a limited set of properties, but you cannot delete a standard field, remove a standard control or rewrite the body of a standard method. Where business logic needs to run differently, you hook into it through the mechanisms the rest of this course covers: Chain of Command wrappers, event handlers, delegates and other extension points that Microsoft deliberately provides.

What each type of element can be extended with. Details and limits are in the lessons listed.
Element typeWhat an extension can doLesson
TableAdd fields, field groups, indexes, relations and delete actions; change some properties; wrap methods2 and 3
FormAdd controls, data sources and data source fields; change some control properties; wrap methods on the form and its nested parts2 and 3
Enum (extensible)Add values2
Extended data typeChange some properties such as label, help text and, for strings, a longer length2
ClassAdd methods and member variables; wrap public and protected methods3
Menu, menu itemAdd menu items to standard menus; change some properties10
Security role, duty, privilegeAdd duties, privileges and permissions10
Query, view, data entityAdd data sources, ranges and fields within limits2
Report (SSRS)Extend the temporary table and data provider; create a copied design9

Models, packages and references

Extensions live in a model, and a model belongs to a package, the unit that is compiled and deployed. Desmond had created the CobaltRidgeCustom model in its own package during the first series, with references to Application Platform, Application Foundation and Application Suite. Those references matter for extensions. A model can only extend elements it can see, so if a requirement touches an element in a package that is not yet referenced, the first step is to add the reference in the model's parameters and rebuild.

Desmond keeps all of Cobalt Ridge's extensions in one model. Some partners split work into several models, for example one per functional area, so that each can be deployed and tested on its own. The trade-off is that models in separate packages cannot share internal code without references, and circular references are not allowed. For a customer of Cobalt Ridge's size, one model with clear naming is simpler. An independent software vendor that sells several products would normally ship one package per product.

The model descriptor summarized. New references appear as soon as a requirement needs an element from another package.
Package:  CobaltRidgeCustom
Model:    CobaltRidgeCustom (layer USR, publisher Cobalt Ridge Manufacturing)
References:
    ApplicationPlatform
    ApplicationFoundation
    ApplicationSuite
    Directory          // added for the vendor contact extension
    SourceDocumentation  // added for purchase line distributions

Naming extension elements

Extension elements follow a naming pattern so that anyone reading the Application Explorer can see what they extend and who owns them. An extension of a table, form, enum or other metadata element takes the name of the base element, a dot and a suffix that identifies the model, such as PurchLine.CRCustom. Class extensions are ordinary classes, so they need a unique class name; the convention is the base name, the model's prefix or a short description, and the word Extension, as in PurchLineCR_Extension or PurchLineCRInspection_Extension. Microsoft's best-practice rules check that class extensions end in _Extension.

New fields, methods and controls added through extensions also carry the model prefix, so CRHeatNumber rather than HeatNumber. The prefix is not decoration. If Microsoft later adds its own field called HeatNumber to PurchLine, your extension would conflict with it at the next update. A prefixed name never collides with a standard one, and it never collides with an independent software vendor's field either.

Naming conventions used in CobaltRidgeCustom.
What you createName patternCobalt Ridge example
Table extensionBaseTable.SuffixPurchLine.CRCustom
Form extensionBaseForm.SuffixPurchTable.CRCustom
Enum extensionBaseEnum.SuffixPurchStatus is not extensible; CRInspectionStatus is new
Class extensionBaseClass + prefix or purpose + _ExtensionPurchLineType_CRInspection_Extension
New field on a standard tablePrefix + nameCRHeatNumber
New method on a standard classPrefix + namecrIsInspectionRequired

Finding what to extend

Before writing an extension, a developer has to find the code that does the work. Prudence's instinct was to search the code for the word Purchase, which returned thousands of hits. Desmond showed her a better route. In the browser, the form's Form information option, under the Options menu, shows the form name, the data source tables and the menu item that opened it. From the form name, Application Explorer leads to the form's methods and its data sources, and from a data source method, Find references in Visual Studio leads to the classes that do the work. For posting logic, the purchase order classes follow a pattern: a form letter class for each type of update, such as confirmation, receipt and invoice, with methods that create and post journal lines.

Reading standard code is part of every extension task. The downloaded reference metadata in the unified developer experience contains the full source of Microsoft's models, so it can be read, searched and stepped through in the debugger even though it cannot be changed. Desmond's rule was that no one writes an extension until they can explain, in a sentence, what the standard code does at the point they want to change.

When there is no extension point

Sometimes the code that needs to change is private, marked final, or inside a method where there is nothing to hook. Microsoft accepts extensibility requests for exactly that situation: a request to add a delegate, make a method wrappable or refactor a long method into smaller extensible ones. A good request explains the business scenario, names the exact class and method, and proposes the smallest change that would solve it. Microsoft reviews requests and, if it accepts them, ships the change in a future service update, so they are a medium-term solution rather than a quick fix. In the meantime the team has to choose another design, such as handling the requirement at a different point in the process.

Extensions and One Version

Finance and operations apps are delivered as One Version: every customer runs a supported recent version, and Microsoft ships service updates several times a year. Customers can pause an update for a limited time, but not indefinitely. That cadence is the reason the extension model exists. A customer whose code depends only on public, extensible members can take each update, recompile and run regression tests. A customer whose code depends on internal details, or who copied a standard method into an extension to change it, inherits the old upgrade problem in a new form. Lesson 11 covers how to keep extensions compatible.

Reading Microsoft's code before extending it

Every extension starts with reading. In the unified developer experience, the source of the standard models is available as reference metadata, and Visual Studio's Application Explorer shows every table, class and form with its methods. Desmond's habit, which he asked Prudence to copy, was to open the standard element, find the method where the behaviour lives, read who calls it and what it calls, and only then decide how to extend it. Find references and Go to definition are the two commands he used most. Reading also reveals the attributes that decide what is allowed, such as Hookable, Wrappable and Replaceable, and any delegates Microsoft has placed in the method for extenders.

Reading is also how a developer finds out that no code is needed. Before the inspection series began, Prudence spent an hour reading the quality management features from the product course and found that quality orders and item test groups already handled incoming tests on castings. The new requirement was narrower: tracking a supplier's certificate by heat number on the purchase line and blocking receipt without it. Knowing exactly what the standard product already did kept the extension small and avoided building a second, competing quality process.

Where extensions live

Cobalt Ridge kept all of its extensions in one model, CobaltRidgeCustom, in its own package, with references to Application Platform, Application Foundation and Application Suite. Desmond explained that some partners split work into several models, for example one per feature or one for code shared between customers, and that this is sensible when features ship on different schedules. A model can only extend elements in the models it references, and circular references are not allowed, so the reference list is part of the design. For a single customer with one development team, one model kept builds, deployments and reviews simple, and that was the choice Cobalt Ridge made in the first series.

Worked problem

Deciding whether a requirement fits the extension model

Marisol's request has four parts: (1) add an inspection flag and a heat number to purchase lines for castings; (2) stop a product receipt from posting if a required certificate has not been recorded; (3) remove the standard Delivery address tab from the purchase line because buyers never use it; (4) give buyers a new number for each inspection certificate.

Show solution
  1. Part 1 is additive: a table extension on PurchLine adds two prefixed fields, and a form extension shows them on the purchase order lines.
  2. Part 2 changes behaviour during posting. It needs an extension point in the receipt posting or validation logic, such as a Chain of Command wrapper or an event handler; lessons 3 to 5 show which.
  3. Part 3 removes a standard control, which an extension cannot do. The alternatives are to hide it with personalization or a saved view for the buyers, or to set a permitted property such as visibility through an extension if the control allows it.
  4. Part 4 is a new number sequence for a new field, built entirely in the model (lesson 6).

Answer: Parts 1, 2 and 4 fit the extension model directly. Part 3 is handled through personalization or a permitted property change rather than by deleting standard metadata.

Common mistakes

  • MistakeCopying a standard method into an extension class and editing the copy.

    InsteadWrap the method with Chain of Command or use an event, so Microsoft's future fixes still run.

  • MistakeAdding fields to standard tables without a prefix.

    InsteadPrefix every new field, method and control with the model prefix, such as CR, to avoid collisions with future standard or ISV elements.

  • MistakeStarting an extension before reading the standard code at that point.

    InsteadUse Form information, Application Explorer and Find references to understand what the standard code does first.

  • MistakeAssuming an extensibility request will arrive in time for go-live.

    InsteadTreat requests as a medium-term fix and design an interim approach.

Summary and key terms

  • Overlayering edited standard code and made upgrades slow; Microsoft has sealed all its models, so changes are made with extensions.
  • An extension adds to an element or changes permitted properties without modifying the original; extensions are combined with the base element at compile time.
  • Extensions live in your own model and package, which must reference the packages it extends.
  • Extension elements and new members carry a model suffix or prefix to avoid collisions.
  • When no extension point exists, an extensibility request asks Microsoft to add one in a future update.
Overlayering
The legacy practice of changing a copy of standard code in a higher layer, no longer possible on sealed models.
Sealed model
A model that other models can extend but not overlayer.
Extension
An element in your own model that adds to or changes permitted properties of an element in another model.
Extensibility request
A request to Microsoft to add an extension point, such as a delegate or a wrappable method, to standard code.
One Version
The delivery approach in which all customers run a recent supported version and receive regular service updates.

Practice problems

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

  1. Why must every new field on PurchLine carry a prefix such as CR?

    Show answer

    To avoid a name collision if Microsoft or an ISV later adds a field with the same name.

  2. What is the first step if an extension needs an element from a package the model does not reference?

    Show answer

    Add the package to the model's references and rebuild.

  3. Can an extension delete a standard control from a form?

    Show answer

    No. Extensions are additive; hide the control through personalization or a permitted property instead.

Lesson quiz · 5 questions

Score 60% or more to complete this lesson.

Take the quiz