MSBA-341 · Lesson 5 of 12 · 19 min

Extending business logic

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

By the fifth clinic Prudence could write a wrapper and a handler without looking anything up. Desmond raised the bar. Knowing the techniques, he said, is half of extension work; the other half is designing logic that survives the next ten service updates and the next three developers. This session was about the extension points Microsoft builds into the application on purpose, about patterns that keep custom logic in one place, and about two newer ways to extend business logic: business events, which tell other systems that something happened, and Copilot extensibility, which lets the assistant in the application call X++.

Designed extension points

Microsoft refactors standard code over time to make it easier to extend. Long methods are split into smaller ones, each doing one step, so that a wrapper can change one step without copying the rest. Delegates are added at decision points. Some methods are marked Replaceable where Microsoft expects substitution. And many features are built on class factories, where the application picks the class to use for a given type of document or line from metadata rather than from a hard-coded switch statement. When the factory can find classes in other models, adding a new type means adding a class, not changing a switch.

Four columns. Delegates: method raises a delegate, your handler fills in the result object. Replaceable: you may skip next, but only for your own condition. Class factory: SysExtension attribute picks your subclass for your enum value. Business events: notify outside systems when something happens.
Extension points Microsoft builds into standard code.

The SysExtension framework

The SysExtension framework is the standard way to build a class factory. A base class defines the behaviour; subclasses carry an attribute that says which value they handle, such as an enum value; and a factory method asks the framework for the subclass whose attribute matches. Because the framework scans all models for attributed subclasses, another model can add a subclass for a new enum value without touching the factory. Many standard features use this pattern, and extensible enums from lesson 2 are often paired with it: a new enum value plus a new attributed subclass is a complete extension.

A SysExtension factory in the CobaltRidgeCustom model. A future model could add a rule for a new category with only a new subclass. The attribute class itself (extending SysAttribute) is not shown.
// Base class and attribute (in CobaltRidgeCustom)
abstract class CRInspectionRule
{
    abstract boolean isSatisfied(PurchLine _line) { }

    public static CRInspectionRule newFromCategory(CRInspectionCategory _category)
    {
        CRInspectionCategoryAttribute attr = new CRInspectionCategoryAttribute(_category);
        return SysExtensionAppClassFactory::getClassFromSysAttribute(
            classStr(CRInspectionRule), attr) as CRInspectionRule;
    }
}

[CRInspectionCategoryAttribute(CRInspectionCategory::Casting)]
class CRInspectionRule_Casting extends CRInspectionRule
{
    boolean isSatisfied(PurchLine _line)
    {
        return _line.CRInspectionStatus == CRInspectionStatus::Received
            || _line.CRInspectionStatus == CRInspectionStatus::Waived;
    }
}

Desmond pointed out that the factory call caches its lookups, which is why the framework performs well even though it uses reflection. He also warned that the attribute class must implement the interface the framework uses to compare attribute values, which is easy to forget and produces a factory that silently returns nothing. Every new factory therefore gets a unit test (covered in MSBA-343) that asks for each known category and checks the class returned.

Keeping custom logic in one place

A second design principle is to keep the business rules in one service class and keep wrappers and handlers thin. In lesson 3 the receipt wrapper and the purchase line validation both needed to know whether a line's inspection was satisfied. If each contained its own if statement, the rule would drift apart the first time someone changed one copy. Instead both call one method on a CRInspectionService class, which in turn uses the rule factory. A wrapper should read like a sentence: call next, ask the service, report the answer.

Layering custom business logic.
LayerResponsibilityExample
Extension (wrapper or handler)Hook into standard code; call next; delegate to a servicePurchLineCRInspection_Extension
Service classHold the business rule and its messagesCRInspectionService::isSatisfied
Rule classesVary the rule by category through a factoryCRInspectionRule_Casting
DataStore state and certificatesPurchLine fields, CRInspectionCertTable

This layering pays off in testing. A service method that takes a purchase line and returns a yes or no can be unit tested directly with SysTest, without posting a receipt. The wrapper becomes so simple that a reviewer can check it at a glance. Desmond also kept parameters, such as which item groups require inspection, in a parameters table rather than in code, so that Annelise could change them as configuration without a release.

Business events

Some logic belongs outside finance and operations apps altogether. Cobalt Ridge's plant scheduling tool was fed by a nightly export of orders, and the MSBA-141 design called for replacing it with a business event. A business event is a message that the application sends when something happens, such as a purchase order being confirmed. Administrators activate events in the business events catalog and choose an endpoint, such as Azure Service Bus, Event Grid, a Power Automate flow or another supported target. The external system receives a small JSON payload and can then call back for more data if it needs it.

Developers can build custom business events. The pattern has three parts: a contract class that defines the payload fields, a business event class that extends BusinessEventsBase and builds the contract from the record, and a call that sends the event at the right point in the process, usually from a Chain of Command wrapper or a data event after the transaction commits. The event is then listed in the catalog with a name, description and category. The next course, MSBA-342, covers business events, endpoints and their reliability in detail; this lesson is only about where they fit in extension design.

Checking whether an event is activated before building and sending it avoids doing the work when no one is listening. Class names are Cobalt Ridge examples.
// Sketch: sending a custom business event after a certificate is recorded
if (BusinessEventsConfigurationReader::isBusinessEventEnabled(classStr(CRCertificateRecordedBusinessEvent)))
{
    CRCertificateRecordedBusinessEvent::newFromCertificate(cert).send();
}

Business events are not a way to run logic inside the transaction. They are sent to an external endpoint and processed outside the user's session, so they suit notifications and integrations, not validations. If the quality team wanted an email on every missing heat number, the business event approach would send a message to a Power Automate flow, which would send the email, keeping the work out of finance and operations entirely.

Extending Copilot in finance and operations apps

Copilot in finance and operations apps is orchestrated by Copilot Studio, and developers can extend it with X++. The pattern Microsoft documents most fully is the client plugin, also called a client action. It lets a user ask Copilot, in natural language, to do something in the client: open a form, fill in values or run a calculation. According to Microsoft's documentation, updated March 2026, client plugins require version 10.0.40 or later, can be developed only in the unified developer experience, and are in preview, so they are not intended for production use.

A client plugin is an X++ class that extends SysCopilotChatAction and is marked as a data contract. A SysCopilotChatActionDefinition attribute gives it an identifier that must begin with MS.PA, a name, a description and a menu item; the menu item's security controls who can use the action. Global actions carry the SysCopilotChatGlobalAction attribute and are available on any form while the Copilot pane is open; form actions are limited to specific forms. Input and output parameters are parm methods decorated with DataMember and SysCopilotChatActionInputParameter or SysCopilotChatActionOutputParameter, and the work happens in an executeAction override. In Copilot Studio, a topic sends an event named with the identifier, and another topic receives the result.

The shape of a client plugin based on Microsoft's documented pattern. Check the exact executeAction signature in the current documentation before building one.
[DataContract]
[SysCopilotChatGlobalAction]
[SysCopilotChatActionDefinition(
    identifierStr(MS.PA.CobaltRidge.InspectionStatus),
    'Inspection status',
    'Shows whether casting lines on the current purchase order are ready to receive',
    menuItemActionStr(CRInspectionStatusAction), MenuItemType::Action)]
public final class CRInspectionStatusChatAction extends SysCopilotChatAction
{
    // parm methods with DataMember and SysCopilotChatActionInputParameter or
    // SysCopilotChatActionOutputParameter, then:
    public void executeAction(SysCopilotChatActionDefinitionAttribute _definition, Object _context)
    {
        // read the current purchase order from the context, ask CRInspectionService,
        // and set the output parameters
    }
}

For logic that should run on the server and be callable by agents, Microsoft's release plans describe exposing X++ business logic to Copilot Studio as AI actions or tools, built on Dataverse custom APIs that call X++ classes. The details have changed across release waves, so the course describes the idea rather than the current attribute names. Whatever the mechanism, Desmond applied the canon rule from the MSBA-141 project: agents and Copilot may look things up, draft and submit, but they never post documents directly. The inspection status action reads and reports; it does not change a purchase order.

Service classes and the parm pattern

Most of the logic Cobalt Ridge added lived in ordinary classes in the model rather than in wrappers or handlers. Desmond's preferred shape was a service class with a construct method, parm methods to set its inputs and a run or validate method to do the work. CRInspectionService, for example, took a purchase line, found the rule for its category, and answered whether a receipt could post. Because the class had no user interface and no dependency on how it was called, the same code served the posting wrapper, the alert job, the client plugin and the unit tests. Keeping logic in such classes also meant the wrappers in lessons 3 and 11 could stay one line long.

Business events step by step

Lesson 5's sketch of CRCertificateRecordedBusinessEvent left out the steps that make a business event usable. The event class extends BusinessEventsBase and carries the BusinessEvents attribute that names its contract, label and module. The contract class extends BusinessEventsContract and has DataMember parm methods for each field the event sends, such as the certificate number, heat number, purchase order and vendor. The code that records a certificate checks whether the event is enabled, using BusinessEventsConfigurationReader::isBusinessEventEnabled, and only then builds and sends it, so there is no cost when nobody subscribes. After deployment, an administrator rebuilds the business event catalog so the new event appears, then activates it against an endpoint. The next course, MSBA-342, covers endpoints and consumers in depth.

The pieces of a custom business event.
PiecePurpose
Event class extending BusinessEventsBaseBuilds the payload and names the contract, label and module
Contract class extending BusinessEventsContractDefines the fields sent, as data members
Trigger in Cobalt Ridge codeSends the event only when it is enabled
Catalog rebuild and activationAdministrator setup after deployment

Choosing how Copilot reaches the feature

Prudence asked how to choose between the ways Copilot can use finance and operations logic. Microsoft offers client plugins, which run X++ in the context of the user's session and the page they are on, and actions exposed through Dataverse, which agents built in Copilot Studio can call from outside the client. A client plugin suited the buyer's question about inspection status on an open purchase order, because the context of the current page mattered. An agent that monitored certificates across all orders would need a server-side action instead. In both cases Cobalt Ridge's rule from the first series held: agents and Copilot may read, draft and submit, but never post.

Documenting extension points of your own

Designing for change has a documentation side. Desmond kept a short page in the project wiki listing the extension points CobaltRidgeCustom offered: the CRInspectionCategory enum, the CRInspectionRule base class and its attribute, the business event and the delegate on the certificate service that announced a certificate had been recorded. Each entry said who might extend it and how. When a later team added the pressure-test requirement in the case study, that page told them where to start without reading the whole model.

Thandeka, who had joined the end of the session, asked how she would know if someone later broke one of these extension points. Desmond pointed to the unit tests: each extension point had a test that used it the way an extender would, such as a test rule class registered for a test category. If a change to the model broke the contract that extenders relied on, the test failed in the build before the change reached a sandbox.

Worked problem

Designing the certificate rule for change

Today only castings need certificates. Piotr expects forgings and pressure-tested valve bodies to need them next year, each with slightly different rules. How should Prudence design the rule so that adding a category is easy?

Show solution
  1. Create a new extensible enum CRInspectionCategory with the value Casting, so future values can be added.
  2. Define an abstract CRInspectionRule class with an isSatisfied method and a factory method using SysExtension.
  3. Implement CRInspectionRule_Casting with the attribute for the Casting value.
  4. Make the receipt wrapper and the validation call one service method that gets the rule from the factory.
  5. Next year, adding forgings means a new enum value and a new attributed subclass; the wrapper and service do not change.

Answer: An extensible enum plus a SysExtension factory turns a future requirement into an addition rather than an edit, which is the same principle Microsoft uses in standard code.

Common mistakes

  • MistakeCopying the same rule into several wrappers and handlers.

    InsteadKeep the rule in one service class and keep extensions thin.

  • MistakeUsing a business event to block a transaction.

    InsteadBusiness events notify external systems after the fact; use validation for blocking rules.

  • MistakeBuilding production features on preview Copilot extensibility.

    InsteadTreat preview features as pilots and check Microsoft's current status before relying on them.

  • MistakeLetting Copilot actions post documents directly.

    InsteadLimit actions to reading, drafting and submitting; keep posting with people and approved processes.

Summary and key terms

  • Microsoft adds delegates, Replaceable methods, smaller methods and class factories to make standard code extensible.
  • The SysExtension framework picks a subclass by attribute, so new cases can be added as new classes.
  • Keep business rules in service classes and keep wrappers and handlers thin and testable.
  • Business events notify external systems through endpoints; custom events use a contract, an event class and a send call.
  • Copilot client plugins extend SysCopilotChatAction and are in preview; agent actions should not post documents directly.
SysExtension framework
A standard framework that finds the subclass whose attribute matches a requested value.
Class factory
Code that chooses which class to instantiate from metadata rather than a hard-coded switch.
Business event
A message sent to an external endpoint when something happens in the application.
Client plugin
An X++ class that lets Copilot in finance and operations apps run an action in the client.
Service class
A class that holds business rules so wrappers and handlers can call them.

Practice problems

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

  1. What two things does adding a new inspection category require in the factory design?

    Show answer

    A new value on the extensible enum and a new subclass with the matching attribute.

  2. Why check whether a business event is enabled before building it?

    Show answer

    To avoid building and sending a payload when no endpoint is listening.

  3. What prefix must a client plugin identifier start with?

    Show answer

    MS.PA.

Lesson quiz · 5 questions

Score 60% or more to complete this lesson.

Take the quiz