Dynamics 365 Business Central: How to deprecate external business events (ExternalBusinessEvent)

Dynamics 365 Business Central

Hi, Readers.
Today I would like to talk about how to deprecate external business events (ExternalBusinessEvent).

Business events provide our partners and customers a mechanism for notifying and triggering their external systems (Dataverse and non-Dataverse) when actions are done on Business Central. The external systems can react and perform other actions in response. With Dataverse, partners and customers can use Power Automate to subscribe to Business Central for its business events and react on other apps in its ecosystem, such as Dynamics 365 Sales or Customer Service, and others built using Power Apps. They can also react on non-Dataverse systems, such as non-Microsoft warehouse management, fulfillment, and e-invoicing services. More details: Business events on Business Central (preview)

Business Central catalog of business events: The following table describes the business events in Business Central catalog. These business events are readily available in version 22.2 and later but must be implemented in an extension in version 22.0 and 22.1

CategoryNameDescription
Accounts PayablePurchase credit memo postedTriggered when a purchase credit memo is posted.
Accounts PayablePurchase invoice postedTriggered when a vendor invoice is posted as part of the Procure-to-Pay process.
Accounts PayablePurchase payment postedTriggered when a vendor payment is posted as part of the Procure-to-Pay process.
Accounts PayablePurchase receipt postedTriggered when goods from a purchase order are received by the internal warehouse/external logistics company. This event can trigger Finance Department to post a purchase invoice.
Accounts ReceivableCustomer blockedTriggered when a customer is blocked for shipping/invoicing.
Accounts ReceivableCustomer unblockedTriggered when a customer is unblocked for shipping/invoicing.
Accounts ReceivableSales credit limit exceededTriggered when the credit limit for a customer is exceeded due to a posted sales invoice/changed credit limit for that customer.
Accounts ReceivableSales credit memo postedTriggered when a sales credit memo is posted.
Accounts ReceivableSales invoice postedTriggered when a sales invoice is posted as part of the Quote-to-Cash process.
Accounts ReceivableSales payment postedTriggered when a customer payment is posted as part of the Quote-to-Cash process.
Accounts ReceivableSales shipment postedTriggered when goods from a sales order are shipped by the internal warehouse/external logistics company. This event can trigger Finance Department to post a sales invoice.
OpportunitiesOpportunity activatedTriggered when an opportunity is activated as part of the Quote-to-Cash process.
OpportunitiesQuote created for opportunityTriggered when a quote is created for an opportunity as part of the Quote-to-Cash process.
OpportunitiesWinning quote converted into sales orderTriggered when a winning quote for an opportunity is converted into a sales order as part of the Quote-to-Cash process.
OpportunitiesOpportunity closed as lostTriggered when a lost opportunity is closed as part of the Quote-to-Cash process.
PurchasingPurchase order releasedTriggered when a purchase order is released to the internal warehouse/external logistics company, so they’re ready to receive goods coming their way. This trigger occurs when the Release button is clicked on Purchase Order page in Business Central.
SalesSales order releasedTriggered when a sales order is released to the internal warehouse/external logistics company, so they’re ready to pick and ship goods. This trigger occurs when the Release button is clicked on Sales Order page in Business Central.

These are defined in AL. These codes are stored in the Exclude_Business_Events extension.
PS: How to list all installed extensions/apps in your Business Central environment (Including hidden apps – “_Exclude_……”)

We can add dependencies settings in the app.json file to download its symbol file.

  "dependencies": [
    {
      "id": "6f2c034f-5ebe-4eae-b34c-90a0d4e87687",
      "name": "_Exclude_Business_Events_",
      "publisher": "Microsoft",
      "version": "24.0.0.0"
    }
  ],

For example, Sales order released:

Customer blocked:

How do we understand the standard code here? Let’s go back to Sales order released. Simply put, there are three steps.
1. Defining External Business Events

ExternalBusinessEvent(Name: Text, DisplayName: Text, Description: Text, Category: Enum, [Version: Text])
Specifies that the method is published as an external business event.

2. Subscribe to the event to specify when it needs to be triggered.

EventSubscriber(ObjectType: ObjectType, ObjectId: Integer, EventName: Text, ElementName: Text, SkipOnMissingLicense: Boolean, SkipOnMissingPermission: Boolean)
Specifies the event to which the method subscribes.

3. Put the procedure created in step 1 into the procedure in step 2.

PS: If you need more detailed instructions, you can refer to Microsoft documentation, Build and install an extension for custom business events.
Sample code provided by Microsoft:

enumextension 50101 MyEnumExtension extends EventCategory
{
   value(0; "Sales")
   {
   }
}

codeunit 50102 MyCodeunit 
{ 
   trigger OnRun()
   begin
   end; 

   [ExternalBusinessEvent('salesorderposted', 'Sales order posted', 'Triggered when sales order has been posted', EventCategory::"Sales")]
   [RequiredPermissions(PermissionObjectType::TableData, Database::"Sales Header", 'R')] // optional
   procedure SalesOrderPosted(salesOrderId: Guid; customerName: Text; orderNumber: Text)
   begin
   end;
   
   [EventSubscriber(ObjectType::Page, Page::"Sales Order", 'OnPostDocumentBeforeNavigateAfterPosting', '', true, true)] 
   local procedure OnPostDocument(var SalesHeader: Record "Sales Header"; var PostingCodeunitID: Integer; var Navigate: Enum "Navigate After Posting"; DocumentIsPosted: Boolean; var IsHandled: Boolean) 
   begin
      SalesOrderPosted(SalesHeader.SystemId, SalesHeader."Sell-to Customer Name", SalesHeader."No."); 
   end;
}

More details: Dynamics 365 Business Central: OnValidate (Field) Trigger in Power Automate (Trigger a flow when a field is modified) – Business events

For long-lived or widely distributed applications, you might need to phase out certain events over time, ensuring that external integrations have sufficient notice to update their subscriptions. This process is managed by deprecating external business events in a predictable way so that consumers of the event are informed and encouraged to transition to new or replacement events. The approach for deprecating an external business event is similar to the standard deprecation process for procedures.
APPLIES TO: Business Central 2025 release wave 1 (v26) and later.

First, mark the event as obsolete pending.

  1. Decorate the procedure with the [Obsolete('<Reason>','<Tag>')] attribute, as you would for any other procedure that is pending deprecation.
  2. Prefix the DisplayName of the ExternalBusinessEvent attribute with an [OBSOLETE] marker. This ensures that the obsoletion is reflected in the name, and external subscribers see the deprecation notice.

Or

Here is a simple example:

In Power Automate:

Then, remove the event in a future version. Great, give it a try!!!😁

More details: Deprecate external business events

END

Hope this will help.

Thanks for reading.

ZHU

コメント

Copied title and URL