Hi Folks,
I recently faced issue where PO confirmation business event was not triggering and failing my interface. Issue was whenever after first PO confirmation if user make change to PO header delivery date or cancellation date and reconfirm the PO, it wont trigger the respective Business event.
[Although there are different reason why business event is not considering this change, while if I make any financial changes like qty, line addition, tax etc, it works fine]
Ok lets see now how I can call a business event from code,
To trigger a business event in X++ code, you need to create a business event contract, an event handler class, and then trigger the event from your X++ code by using the BusinessEvent::newFromTable() and businessEvent.send() methods. (Also, configure the event in the business event catalog if its not configured)
1. Create a Business Event Contract:
Purpose: Defines the data that will be sent with the business event. For reference check CustFreeTextInvoicePostedBusinessEventContract.
2. Create an Event Handler Class:
Purpose: Handles the event when it's triggered, allowing you to perform actions based on the event.
For reference check CustTable_BusinessEvent_EventHandler
3. Trigger the Business Event from X++ Code:
Purpose: Use the BusinessEvent::newFromTable() and businessEvent.send() methods to trigger the event.
here is complete code sample,