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.

 	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.

  1. Add a static newFrom<my_buffer> method, filling in the my_buffer piece with the table buffer that is used to initialize the business event contract.

    static public SalesInvoicePostedBusinessEvent
    newFromCustInvoiceJour(CustInvoiceJour _custInvoiceJour)
        SalesInvoicePostedBusinessEvent businessEvent = new
        return businessEvent;
  2. Add private parm methods to maintain the internal state of the class.

    private CustInvoiceJour parmCustInvoiceJour(CustInvoiceJour_custInvoiceJour = custInvoiceJour)
        custInvoiceJour = _custInvoiceJour;
        return custInvoiceJour;
  3. Add the buildContract method. The method must be decorated with the Wrappable(true) and Replaceable(true) attributes, and it will only be called when a business event is enabled for a company.

    [Wrappable(true), Replaceable(true)]
    public BusinessEventsContract buildContract()

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.

  1. Extend the BusinessEventContract class, ensuring that it's decorated with the DataContract attribute.

    public final class SalesInvoicePostedBusinessEventContract extends
  2. 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;
  3. Add a private initialization method by using the initialize name. This method sets the business event contract class's private state, based on data that is provided through the static 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;
  4. Add a static constructor method.

    public static SalesInvoicePostedBusinessEventContract
    newFromCustInvoiceJour(CustInvoiceJour _custInvoiceJour)
        var contract = new SalesInvoicePostedBusinessEventContract();
        return contract;
  5. Add parm methods to access the contract state. These methods should be decorated with the DataMember('') and BusinessEventsDataMember('') attributes. To populate the data contract's internal state, you might need additional retrieval methods, which should be shown as private and called from the initialize method.

    public CustInvoiceAccount parmInvoiceAccount(CustInvoiceAccount_invoiceAccount = invoiceAccount)
        invoiceAccount = _invoiceAccount;
        return invoiceAccount;