Wednesday 7 October 2015

Event Types - NAV2016 - Events Part 2


Microsoft Dynamics NAV supports different types of events for different purposes. This topic describes the different types.


Business Events

A business event is a custom event. It defines a formal contract that carries an implicit promise not to change in future releases. It is the expectation that business events are published by solution ISVs, including Microsoft.
Business events can be compared with publicly released APIs on which 3rd party solution provider develop integrations and additions. Therefore, the downstream cost of making changes to a business event implementation can be considerable for those who use the event in their applications. There may be some cases where changes are required; however, you should keep these to an absolute minimum.

Development considerations
A typical business event reflects changes in “state” with regards to a process. This makes them very well suited for workflow. An example of a business event could be when a sales order has been posted. It is important to note that business events should not be tied to the implementation-details, such as the tables or fields in which the data is stored. Preferably, the event publisher developer should be free to change the implementation, while still keeping the business event intact.

Documentation
Business events must be documented with the solution, including the before-state and after-state of the events.


Integration Events

An integration event is also a custom event, like a business event, except that it does not carry the same promise of not changing, nor does it have the restriction not to expose implementation details.
The main purpose of integration events is to enable the integration of other solutions with Microsoft Dynamics NAV without having to perform traditional code modifications.

Development considerations
An integration event can be changed to a business event later. At which time, it must adhere to the same implied contract and commitment as any business event. It can also simply be designed-in hook points for external add-ons.

Documentation
There are no formal requirements for integration events because they follow local partner best practices.


Trigger Events

Unlike business and integration events which must be programmed, trigger events are predefined events. Trigger events are raised by the system when it performs database table operations, such as deleting, inserting, modifying, and renaming a record. Trigger events are closely associated with the table triggers for database operations: OnDelete, OnInsert, OnModify, OnRename, and OnValidate (for fields).


Available Trigger Events

For each database operation, there is a "before" and "after" trigger event with a fixed signature. The following table describes the available trigger events:

Trigger event with signature
Description
OnBeforeDeleteEvent(VAR Rec: Record, RunTrigger: Boolean) Executed before a record is deleted from a table.
OnAfterDeleteEvent(VAR Rec: Record, RunTrigger: Boolean) Executed after a record is deleted from a table.
OnBeforeInsertEvent(VAR Rec: Record, RunTrigger: Boolean) Executed before a record is inserted in a table.
OnAfterInsertEvent(VAR Rec: Record, RunTrigger: Boolean) Executed after a record is inserted in a table.
OnBeforeModifyEvent(VAR Rec: Record, VAR xRec: Record, RunTrigger: Boolean) Executed before a record is modified in a table.
OnAfterModifyEvent(VAR Rec: Record, VAR xRec: Record, RunTrigger: Boolean) Executed after a record is modified in a table.
OnBeforeRenameEvent(VAR Rec: Record, VAR xRec: Record, RunTrigger: Boolean) Executed before a record is renamed in a table.
OnAfterRenameEvent(VAR Rec: Record, VAR xRec: Record, RunTrigger: Boolean) Executed after a record is renamed in a table.
OnBeforeValidateEvent(VAR Rec: Record, VAR xRec: Record, RunTrigger: Boolean; CurrentFieldNo: Integer) Executed before a field is validated when its value has been changed.
OnAfterValidateEvent(VAR Rec: Record, VAR xRec: Record, RunTrigger: Boolean; CurrentFieldNo: Integer) Executed after a field is validated when its value has been changed.

The following table describes the parameters of the trigger events:

Parameter
Type
Description
Rec Record The table that raises the event.
xRec Record The table that raises the event.
RunTrigger Boolean Specifies whether to execute the code in the event trigger when it i invoked. If this parameter is true, the code will be executed. If this parameter is false, then the code is not executed.
CurrentFieldNo Integer The number of the field that raises the event.


Development Considerations

Trigger events are published by the runtime and cannot be raised programmatically.
The relative order of execution of trigger events, table triggers, and database operations is as follows:

Order
Item
Example
1 Trigger event (before) OnBeforeDeleteEvent
2 Table trigger OnDelete
3 Global table trigger in codeunit 1 OnDatabaseDelete
4 Database operations Delete the record
5 Trigger event (after) OnAfterDeleteEvent

Trigger events do not appear in C/AL Editor from the Table Designer in the Microsoft Dynamics NAV Development Environment.

Subscriber functions cannot access the sender and or access global variables.


No comments:

Post a Comment