Business Event in D365F&O

 Business Events

Business events provide a mechanism that lets external systems receive notifications from finance and operations apps. By using this mechanism, you can perform business actions in response to the business events.

Business events occur when a business process runs. During a business process, users who participate in it perform business actions to complete the tasks that make up the business process.

A business action that a user performs can be either a workflow action or a nonworkflow action. Approval of a purchase requisition is an example of a workflow action, whereas confirmation of a purchase order is an example of a nonworkflow action. Both types of actions can generate business events that external systems can use in integration and notification scenarios.

Prerequisites

You can consume business events by using Microsoft Power Automate and Azure messaging services. Therefore, you must bring your subscriptions to these assets to use business events.

We need endpoints values before configure BE in F&O. 
BE supports:
  • Azure service bus que
  • Azure service bus topic
  • Event grid
  • Event hub
  • HTTPS
  • Blob storage
In F&O BE can configure in BusinessEvent Catalogue form. 


From coding side. we need two class to extends BusinessEventBase and BusinessEventContract.

Contract class for initialise the values and base class to send data to Azure services.

BusinessEventContract: 

[DataContract]
public final class SalesBusinessEventContract extends BusinessEventsContract
{
    private CustAccount     custAccount;
    private SalesId         salesId;

public static SalesBusinessEventContract newFromSalesTable(SalesTable _salesTable)
{
    var contract = new SalesBusinessEventContract();
    contract.initialize(_salesTable);
    return contract;
}
 [DataMember('CustomerId'), BusinessEventsDataMember("@SYS7149")]
 public CustAccount parmCustomerId(CustAccount _custAccount = custAccount)
 {
     custAccount = _custAccount;
     return custAccount;
 }
 [DataMember('OrderId'), BusinessEventsDataMember("@SYS9694")]
 public SalesId parmOrderId(SalesId _salesId = salesId)
 {
     salesId = _salesId;
     return salesId;
 }
 private void initialize(SalesTable _salesTable)
 {
     custAccount     = _salesTable.CustAccount;
     salesId         = _salesTable.SalesId;

}

}

BusinessEventBase:

[BusinessEvents(classStr(SalesBusinessEventContract),
    "SalesOrderStatusChange",
    "SalesOrderStatusChangeDescription",
    ModuleAxapta::SalesOrder)]
public final class SalesBusinessEvent extends BusinessEventsBase
{
 private SalesTable salesTable;
 public static SalesBusinessEvent newFromSalesTable(SalesTable _salesTable)
 {
     SalesBusinessEvent businessEvent = new SalesBusinessEvent();
     businessEvent.parmSalesTable(_salesTable);
     return businessEvent;
 }
private void new()
{
}
private SalesTable parmSalesTable(SalesTable _salesTable = salesTable)
{
    salesTable = _salesTable;
    return salesTable;
}
 public BusinessEventsContract buildContract()
 {
     return SalesBusinessEventContract::newFromSalesTable(salesTable);
 }
}

Below is the code to call business events
 if (BusinessEventsConfigurationReader::isBusinessEventEnabled(classStr(SalesBusinessEvent)))
 {
     SalesBusinessEvent::newFromSalesTable(_salesTable).send();
 }
    To reflect the Business event class in catalouge click on this option


Comments

Popular posts from this blog

In ax D365F&O post packing slip from shipment through code x++.

Multi select lookup in UI Builder class in D365F&O through x++ code.

Custom label layouts and printing In D365 F&O