Create a new business event
To implement a new business event, you need to build a contract, build the event, and then add code to send the event.
Two classes are implemented for a new event: a business event class and
a business events contract class. The business event class extends the
BusinessEventsBase
class and supports constructing the
business event, building the payload, and sending the business event.
The name should include the noun or phrase that corresponds with the
event, followed by the BusinessEvent
suffix, such as
CustomerInvoicePostedBusinessEvent
.
First you will need to create the SalesInvoicePostedBusinessEvent class.
Extend the BusinessEventsBase
class. Labels must be defined for the name and description arguments, but the at "@" symbol should be left out to avoid storing localized data. The BusinessEvents
attribute provides the business events framework with information about the business event's contract, name, and description.
[BusinessEvents(classStr(SalesInvoicePostedBusinessEventContract),
"AccountsReceivable:SalesOrderInvoicePostedBusinessEventName","AccountsReceivable:SalesOrderInvoicePostedBusinessEventDescription",ModuleAxapta::SalesOrder)]
public class SalesInvoicePostedBusinessEvent extends BusinessEventsBase
After the class is created, use the following procedure to add methods to your class. The code examples define the SalesInvoicePostedBusinessEvent
event.
Add a static
newFrom<my_buffer>
method, filling in themy_buffer
piece with the table buffer that is used to initialize the business event contract.static public SalesInvoicePostedBusinessEvent newFromCustInvoiceJour(CustInvoiceJour _custInvoiceJour) { SalesInvoicePostedBusinessEvent businessEvent = new SalesInvoicePostedBusinessEvent(); businessEvent.parmCustInvoiceJour(_custInvoiceJour); return businessEvent; }
Add
private parm
methods to maintain the internal state of the class.private CustInvoiceJour parmCustInvoiceJour(CustInvoiceJour_custInvoiceJour = custInvoiceJour) { custInvoiceJour = _custInvoiceJour; return custInvoiceJour; }
Add the
buildContract
method. The method must be decorated with theWrappable(true)
andReplaceable(true)
attributes, and it will only be called when a business event is enabled for a company.[Wrappable(true), Replaceable(true)] public BusinessEventsContract buildContract() { return SalesInvoicePostedBusinessEventContract::newFromCustInvoiceJour(custInvoiceJour); }
Business events contract class
The Business events contract class extends the
BusinessEventsContract
class. It defines the payload of
the business event and allows the contract to be populated at runtime.
Use the following steps to extend the BusinessEventContract
class and add methods to the class. The code examples define the
SalesInvoicePostedBusinessEventContract
event.
Extend the
BusinessEventContract
class, ensuring that it's decorated with theDataContract
attribute.[DataContract] public final class SalesInvoicePostedBusinessEventContract extends BusinessEventsContract
Add
private
variables to hold the contract state.private CustInvoiceAccount invoiceAccount; private CustInvoiceId invoiceId; private SalesIdBase salesId; private TransDate invoiceDate; private DueDate invoiceDueDate; private AmountMST invoiceAmount; private TaxAmount invoiceTaxAmount; private LegalEntityDataAreaId legalEntity;
Add a
private
initialization method by using theinitialize
name. This method sets the business event contract class's private state, based on data that is provided through thestatic
constructor method.private void initialize(CustInvoiceJour _custInvoiceJour) { invoiceAccount = _custInvoiceJour.InvoiceAccount; invoiceId = _custInvoiceJour.InvoiceId; salesId = _custInvoiceJour.SalesId; invoiceDate = _custInvoiceJour.InvoiceDate; invoiceDueDate = _custInvoiceJour.DueDate; invoiceAmount = _custInvoiceJour.InvoiceAmountMST; invoiceTaxAmount = _custInvoiceJour.SumTaxMST; legalEntity = _custInvoiceJour.DataAreaId; }
Add a
static
constructor method.public static SalesInvoicePostedBusinessEventContract newFromCustInvoiceJour(CustInvoiceJour _custInvoiceJour) { var contract = new SalesInvoicePostedBusinessEventContract(); contract.initialize(_custInvoiceJour); return contract; }
Add
parm
methods to access the contract state. These methods should be decorated with theDataMember('')
andBusinessEventsDataMember('')
attributes. To populate the data contract's internal state, you might need additional retrieval methods, which should be shown asprivate
and called from theinitialize
method.[DataMember('InvoiceAccount'), BusinessEventsDataMember("@AccountsReceivable:InvoiceAccount")] public CustInvoiceAccount parmInvoiceAccount(CustInvoiceAccount_invoiceAccount = invoiceAccount) { invoiceAccount = _invoiceAccount; return invoiceAccount; }