Event handler methods

The event handler methods are static public methods that you add to the public static class in your extension assembly. In most cases, you will have one method for each event from the web service that your extension assembly will handle events for.

Event handler argument types

The names you use for the static methods aren't critical. The name should describe the action that is being performed by the event handler. The method signature for each static method is important. The parameters must match what the Dynamics GP service is expecting. Each event handler method has the following basic form:

public static void method_name(object sender, EventArgsType e)

In place of EventArgsType you must specify the appropriate type for the type of event the static method is responding to. The following table lists the event types and the event arguments type that should be used.

Event

Event Arguments Type

Retrieved

BusinessObjectEventArgs

DefaultingForCreate

BusinessObjectEventArgs

ValidatingForCreate

BusinessObjectValidateEventArgs

Creating

BusinessObjectEventArgs

Created

BusinessObjectEventArgs

DefaultingForUpdate

BusinessObjectUpdateEventArgs

ValidatingForUpdate

BusinessObjectValidateForUpdateEventArgs

Updating

BusinessObjectUpdateEventArgs

Updated

BusinessObjectUpdateEventArgs

DefaultingForDelete

BusinessObjectEventArgs

ValidatingForDelete

BusinessObjectValidateEventArgs

Deleting

BusinessObjectEventArgs

Deleted

BusinessObjectEventArgs

DefaultingForVoid

BusinessObjectEventArgs

ValidatingForVoid

BusinessObjectValidateEventArgs

Voiding

BusinessObjectEventArgs

Voided

BusinessObjectEventArgs

For example, the static event handler method that responds to an Updating event from the Dynamics GP service would look like the following:

public static void UpdateItem(object sender, BusinessObjectUpdateEventArgs e)

Writing event handler methods

The event handler method must perform the action to respond to the web service event, such as retrieving extended data for an object from the database. Properties passed in with the event arguments help the event handler complete its work. The following table lists the properties available with the event arguments.

Property

Description

BusinessObject

The complete business object for which the service event is occurring.

Context

The Context object passed with the service call. This object contains information used in processing the event, such as the OrganizationKey.

OriginalBusinessObject

For update events, the complete business object as it existed before it was updated.

Policy

The Policy object passed with the service call.

ValidationResult

For validation events, the collection of validation warnings and errors. If the event handler encounters validation issues, it must add them to this collection.

Event handler methods frequently need to access the Dynamics GP database to complete their actions. Objects available from the Microsoft.Dynamics.Common assembly are provided to help with these tasks. The examples provided in the following sections demonstrate how to perform these database actions.

The event handler methods also need to work with the Extension objects that contain extended data for business objects. The examples provided show the techniques needed to work with the ExtensionList collection, as well as the XML element included with each Extension object.