MSBA-342 · Lesson 5 of 12 · 21 min
Business events
▶ Video coming soon A video version of this lesson is on the way.
At the end of the previous clinic series, Prudence had written a business event called CRCertificateRecordedBusinessEvent. It fired whenever a foundry inspection certificate was recorded against a casting purchase line, and at the time its only consumer had been a test endpoint. Now the plant quality system at Akron was ready to listen. Teodora Brisebois, the plant quality manager, wanted every certificate to appear in her system within minutes, with the heat number and the result, so that the quality engineers could release castings to the machining cell without phoning purchasing. And Piotr Vasquez-Lind wanted the nightly scheduling file replaced by something that told the plant when a configured pump order was confirmed. Both requests asked the same thing of the application: when something happens, tell someone.
That is the job of business events. This clinic covered how they work, how they are activated and sent to endpoints, how to write a custom one in X++, and the design rules that make them useful rather than noisy.
What business events are
A business event is a notification that something meaningful happened in a business process: an invoice was posted, a purchase order was confirmed, a certificate was recorded. When the event occurs, the application builds a small JSON payload describing it and sends that payload to one or more endpoints outside finance and operations apps. Systems that care about the event subscribe to the endpoint and react. The application does not wait for them, does not know who they are, and does not need to change when a new consumer appears.
That loose coupling is the difference between events and the patterns in earlier clinics. With OData or a recurring export, the outside system asks; it must poll, and it learns about changes late or wastefully. With a business event, the application announces, and consumers learn about the change as soon as it is committed. Microsoft's documentation is firm about one limit: business events are lightweight notifications and should not be treated as a mechanism for exporting data. A consumer that needs more than the payload should read the details through OData after it receives the event.
The catalog, endpoints and activation
Business events are managed in the business events catalog under System administration, Set up, Business events. The catalog lists every event in the application with its category (usually the module that raises it), a description and the fields of its payload. A Download schema button produces the JSON schema of the payload, which is exactly what an outside team needs to start building a consumer. The catalog is rebuilt during database synchronization; if a newly deployed custom event does not appear, the Manage menu has a command to rebuild it.
Events are not active by default. To use one, an administrator first creates an endpoint: a destination such as an Azure Service Bus queue or topic, an Azure Event Grid topic, an HTTPS endpoint, or another supported type, each configured with the Azure resource and the credentials the application needs to send to it, usually held in Azure Key Vault. Then the administrator activates the event, choosing one or more endpoints and, optionally, a legal entity. If the legal entity is left blank, the event is active in all legal entities. Power Automate is different: a flow subscribes to a business event directly from the flow designer through the Fin and Ops Apps connector trigger, and the subscription creates the activation itself. Users who build such flows need the privilege to subscribe to business events, and they can only see events assigned to their roles.
| Setting | Default | What it controls |
|---|---|---|
| Processing threads | Up to 4 per batch server | How many threads send events in parallel |
| Bundle size | Configurable | How many events each thread picks up at once |
| Retry count | 3 | How many times sending is retried before the event is logged as an error |
| Wait time between retries | 1,000 milliseconds | Pause between retries |
| Endpoint timeout | 10 seconds | How long a send waits for the endpoint |
Every payload carries a control number that consumers can use to detect duplicates, because delivery is at least once rather than exactly once. Events are also not guaranteed to arrive in the order they occurred. A consumer must be written with both facts in mind: process each control number once, and use the business data in the payload, such as a change date, to decide whether a later event supersedes an earlier one.
Writing a custom business event
A custom business event has two classes. The event class extends BusinessEventsBase and carries the BusinessEvents attribute, which names the contract class, the labels for the event's name and description, and the module the event belongs to. It holds the record the event is about, offers a static constructor that takes that record, and implements buildContract to produce the payload. The contract class extends BusinessEventsContract, carries the DataContract attribute, and has a parm method for each payload field with the DataMember attribute for the JSON name and the BusinessEventsDataMember attribute for the description shown in the catalog. Microsoft's naming convention is a noun phrase, a past-tense verb and the suffix BusinessEvent, as in VendorInvoicePostedBusinessEvent.
[BusinessEvents(classStr(CRPumpOrderConfirmedBusinessEventContract),
'CRCustom:PumpOrderConfirmedEventName',
'CRCustom:PumpOrderConfirmedEventDescription',
ModuleAxapta::SalesOrder)]
public class CRPumpOrderConfirmedBusinessEvent extends BusinessEventsBase
{
private SalesLine salesLine;
private SalesLine parmSalesLine(SalesLine _salesLine = salesLine)
{
salesLine = _salesLine;
return salesLine;
}
public static CRPumpOrderConfirmedBusinessEvent newFromSalesLine(SalesLine _salesLine)
{
CRPumpOrderConfirmedBusinessEvent businessEvent = new CRPumpOrderConfirmedBusinessEvent();
businessEvent.parmSalesLine(_salesLine);
return businessEvent;
}
private void new()
{
}
[Wrappable(false), Replaceable(false)]
public BusinessEventsContract buildContract()
{
return CRPumpOrderConfirmedBusinessEventContract::newFromSalesLine(salesLine);
}
}[DataContract]
public final class CRPumpOrderConfirmedBusinessEventContract extends BusinessEventsContract
{
private SalesIdBase salesId;
private InventTransId lotId;
private ItemId itemId;
private str configuration;
private SalesQty quantity;
private DateTimeIso8601 confirmedShipDate;
private str lineStatus;
private LegalEntityDataAreaId legalEntity;
public static CRPumpOrderConfirmedBusinessEventContract newFromSalesLine(SalesLine _salesLine)
{
var contract = new CRPumpOrderConfirmedBusinessEventContract();
contract.initialize(_salesLine);
return contract;
}
protected void initialize(SalesLine _salesLine)
{
salesId = _salesLine.SalesId;
lotId = _salesLine.InventTransId;
itemId = _salesLine.ItemId;
configuration = _salesLine.inventDim().configId;
quantity = _salesLine.SalesQty;
confirmedShipDate = DateTimeUtil::newDateTime(_salesLine.ShippingDateConfirmed, 0);
lineStatus = enum2Symbol(enumNum(SalesStatus), _salesLine.SalesStatus);
legalEntity = _salesLine.DataAreaId;
}
private void new()
{
}
[DataMember('SalesOrder'), BusinessEventsDataMember('Sales order number')]
public SalesIdBase parmSalesId(SalesIdBase _v = salesId) { salesId = _v; return salesId; }
[DataMember('LotId'), BusinessEventsDataMember('Line lot ID')]
public InventTransId parmLotId(InventTransId _v = lotId) { lotId = _v; return lotId; }
// ... ItemId, Configuration, Quantity, ConfirmedShipDate, LineStatus, LegalEntity
}Several rules in this code come straight from Microsoft's guidance. RecId values must not appear in a payload; use the alternate key, here the sales order and the line's lot ID. Enum values must be converted to their symbols. Dates should use the DateTimeIso8601 type or a type derived from it, so that consumers receive a readable ISO 8601 date instead of an older serialized form. The initialize method is protected so that a future extension can add fields through chain of command, and it uses private helper methods for anything complicated.
Sending the event
The event is sent by creating it and calling send. Microsoft's guidance is to send the event regardless of whether it is enabled, because the framework checks activation itself and only builds the contract for companies where the event is active. A check with BusinessEventsConfigurationReader and isBusinessEventEnabled is only worth adding when preparing the event is expensive, for example when it requires a query in a loop. Sending is tied to the commit of the surrounding transaction: if the transaction is aborted, the event is not sent. That is exactly the behavior a consumer needs, because it never hears about a confirmation that was rolled back.
// In the CobaltRidgeCustom extension of the sales confirmation posting
// (the wrapped method name is illustrative; see MSBA-341 on choosing a hook)
protected void endPost()
{
next endPost();
SalesLine salesLine;
while select salesLine
where salesLine.SalesId == this.parmSalesTable().SalesId
&& salesLine.CRConfiguredPump == NoYes::Yes
{
CRPumpOrderConfirmedBusinessEvent::newFromSalesLine(salesLine).send();
}
}Where to send an event is the hardest design decision. Microsoft recommends capturing events at the level of business logic, not table writes. If the event were sent from the sales line insert method, it would fire for every draft line, every copy and every data import, which is noise; and it could miss confirmations that update lines through set-based code. Sending from the confirmation posting means the event fires once, when the business process actually reaches the point the plant cares about. Desmond's three tests for any business event were the ones Microsoft describes: it should be durable (it reflects a committed fact), targeted (it fires for the business moment, not a technical one), and noiseless (consumers do not need to filter out events they do not care about).
Consuming the certificate event
For the plant quality system, Desmond chose Azure Service Bus. The certificate event was activated for CRCA and CRUS with a Service Bus endpoint pointing at a topic called cr-quality. A subscription on the topic delivered events to the quality system's adapter, which read each message, checked the control number against the ones it had already processed, and created a release record for the casting heat. Service Bus suited this consumer because it holds messages durably when the consumer is down, supports retries and dead-letter queues, and lets subscribers filter on the category, event ID and legal entity fields of the message. If the plant system was offline for maintenance on a Sunday, Monday morning's backlog would still be there.
{
"BusinessEventId": "CRCertificateRecordedBusinessEvent",
"BusinessEventLegalEntity": "crca",
"ControlNumber": 5637189120,
"EventId": "0A6C3F0E-...",
"EventTime": "/Date(1763655600000)/",
"MajorVersion": 0,
"MinorVersion": 0,
"PurchaseOrder": "CRCA-PO-001842",
"LineNumber": 3,
"HeatNumber": "FX-26-1187",
"CertificateId": "CRCA_INSP-000214",
"InspectionStatus": "Received",
"RecordedDate": "2026-11-20T00:00:00Z"
}For the plant scheduling tool, the consumer was simpler and Piotr's team wanted to own it, so Desmond proposed Power Automate: a flow triggered by the pump order confirmed event that called the scheduling tool's own web API. The flow would be built in the UAT sandbox in December and switched on in production alongside the old nightly file in the first quarter of 2027, with the file retired once both had matched for a month.
Monitoring and errors
When sending fails after the retries are exhausted, the event appears in the catalog's errors view with the endpoint and the error message, and can be resent from there once the cause is fixed. Deactivating an event pauses it and keeps its error history. Desmond added two checks to the support runbook: review business event errors daily during the first month after go-live, and alert the integration owner if the Service Bus dead-letter queue for cr-quality ever contained a message.
Choosing an endpoint type
The three endpoint types in the figure suit different consumers, and Desmond gave Prudence a simple way to choose. Azure Service Bus queues and topics are for a known consumer that must not lose a message: they store messages until the consumer takes them, retry, and move poison messages to a dead-letter queue. Azure Event Grid is for fan-out to many subscribers, often serverless functions, with push delivery and filtering, where each subscriber should react quickly and the publisher does not care how many there are. Power Automate is for business-owned automation built by makers: notifications, approvals and small updates to other systems, where the convenience of building in the flow designer matters more than raw throughput. Microsoft also documents HTTPS and other endpoint types, and every endpoint type requires the customer's own Azure subscription or Power Platform environment.
For each event in the register, he asked three questions. Must every event be processed even if the consumer is down for a day? Then Service Bus. Will several unrelated consumers react, or is one expected soon? Then Event Grid. Is the consumer a person's workflow rather than a system? Then Power Automate. The certificate event went to Service Bus. The pump order event went to Power Automate for now, with a note that if the scheduling tool's vendor ever offered a durable adapter, a Service Bus topic would be better. A future event about warranty claims approved went to Event Grid in the plan, because the finance team expected both a Teams notification and a supplier-recovery function to react to it.
Extending standard events and payloads
Many business moments already have standard events: vendor invoice posted, purchase order confirmed, sales invoice posted, workflow events and many more. Before writing a custom event, Prudence searched the catalog. For the plant scheduling tool, no standard event carried the configuration of the pump and fired at confirmation of the line, which is why a custom one was justified. Where a standard event is close but missing a field, the contract class can be extended: because initialize is protected and the contract follows the documented pattern, an extension class can wrap it with chain of command, set an extra private field, and add a parm method with the DataMember and BusinessEventsDataMember attributes. Microsoft's guidance asks that extension fields follow the usual extension naming rules so that two vendors' additions do not collide.
Desmond also warned against the opposite temptation: adding so many fields to a payload that the event becomes an export. The certificate event carried the purchase order, line, heat number, certificate ID, status and date. If the quality system wanted the supplier's full address or the line's cost, it should read them through OData using the keys in the payload. A payload that carries only what every consumer needs stays fast, stays stable, and does not leak data to consumers who should not have it.
Security of events
A business event leaves the application without a user attached. Anyone who can read the endpoint can read every payload sent to it. That makes endpoint security part of data security. The Service Bus topic for quality events used its own namespace, access was granted only to the quality system's identity, and the connection secret lived in Azure Key Vault, where the application read it through the endpoint configuration. Thandeka asked one question during the review that changed the design slightly: did the certificate payload contain anything a casting supplier should not see? It did not, but the question was the right one, and the register gained a column for payload sensitivity.
Worked problem
Placing a business event
Prudence proposes sending CRCertificateRecordedBusinessEvent from the insert method of CRInspectionCertTable. What could go wrong, and where should it go instead?
Show solution
- The table insert runs for every insert, including data management imports during cutover, so the quality system would receive thousands of historic certificates as if they were new.
- Certificates corrected by deleting and re-entering would produce two events for one business fact.
- Set-based inserts that skip the insert method would produce no event at all.
- The business moment is recording a certificate against a purchase line, which happens in the CRInspectionCertService method that the form and the receipt check call.
Answer: Send the event from the certificate recording service method, where it fires once for the business action, and let cutover loads bypass it.
Common mistakes
MistakeUsing business events to push full records to a data warehouse.
InsteadUse events for notifications and analytics features or exports for data.
MistakePutting RecId values and enum integers in the payload.
InsteadSend natural keys and enum symbols.
MistakeAssuming events arrive once and in order.
InsteadDeduplicate on the control number and use business dates to order updates.
MistakeSending an event from a table insert method.
InsteadSend it from the business logic that represents the real business moment.
Summary and key terms
- Business events notify outside systems when a business moment occurs, after the transaction commits.
- Events are activated in the catalog per legal entity and sent to endpoints such as Service Bus, Event Grid or Power Automate.
- A custom event has an event class extending BusinessEventsBase and a contract class extending BusinessEventsContract.
- Payloads use natural keys, enum symbols and ISO 8601 dates, and stay small.
- Consumers must handle duplicates and out-of-order delivery.
- Business event
- A notification sent to outside endpoints when a business moment occurs in finance and operations apps.
- Business events catalog
- The page that lists events, their payload fields and schemas, and where they are activated.
- Endpoint
- A configured destination, such as a Service Bus queue, to which events are sent.
- Activation
- Turning on an event for one or all legal entities and assigning endpoints.
- Event contract
- The class that defines the payload fields of a business event.
- Control number
- A number in each payload that consumers use to detect duplicates.
Practice problems
Work each problem on paper first, then reveal the answer to check.
Why is it safe to call send without checking whether the event is enabled?
Show answer
The framework checks activation and only builds the contract where the event is active; the explicit check is only worth adding when preparing the event is expensive.
What happens to an event if the transaction that raised it is aborted?
Show answer
It is not sent, because sending is tied to the commit.
Why did Desmond choose Service Bus for the quality system?
Show answer
It holds messages durably while the consumer is down, retries, supports dead-letter queues and allows filtering.
Lesson quiz · 5 questions
Score 60% or more to complete this lesson.
Create a free account to save your progress, take quizzes and earn a certificate.