Wednesday, July 15, 2015

Adding a New Event Type in the Alerts Framework of Microsoft Dynamics AX 2012

Overview

Alerts are used to notify users about critical events that occur in Microsoft Dynamics AX.
Microsoft Dynamics AX uses Alerts framework to implement Alerts functionality. It contains a number of event types that can be used for the notification of critical events. However, the Alerts framework can also be extended to add more event types depending upon user requirements.

Pre-requisites

  1. Microsoft Dynamics AX 2012
  2. Batch server must be configured

Important Concepts

Events

Event refers to any activity or occurrence detected by the system in response to a user or a system action. Alerts framework in Microsoft Dynamics AX monitors two types of events, change-based events and due date events.

Change-based events

A change-based event is an event that occurs whenever there is any data insertion, deletion or update activity in the system. It is also referred to as a CUD (Create/Update/Delete) event.

Due date events

Due date events are event that occur whenever a date specified in the system is reached.

EventType Class

To create a new type of event in Alerts framework the EventType class is used. The new event class must inherit either from EventType class or any of its subclasses.
The most important members of EventType class are as follows:
  1. OriginalValue – The old value of the field
  2. CurrentValue – The current/new value of the field
  3. xValue – It is the event parameter, or the value to be monitored
  4. TypeTrigger – It is an enum that determines what caused the event to occur
The most important methods of EventType class are as follows:
  1. description – This method defines the label of the event and therefore must be implemented
  2. isMatchingRule – This defines the condition whether the rule matches the event condition or not
  3. isValidEventType – This method defines the data types for which event can be applied. The alert rule can only be created for the defined data types
  4. isRequiringX – This method defines whether the event requires a value for the event parameter or not. If it returns true, then the field for parameter on the Create alert rule form is enabled, otherwise it is disabled
  5. isFieldRelated – This determines whether the event relates to a field or not
These various fields and methods are used depending upon the scenario to be implemented

Scenario

As part of this tutorial, a new event type will be added in Microsoft Dynamics AX which will generate an alert if the value of a field reaches zero (0)

Steps

  1. First of all create a new class. Open AOT àClasses
  2. Right Click on Classes, choose New Class, and name it EventTypeIsZero
  3. Open the class declaration by right clicking on it and select View Code
  4. Extend the newly created class with EventTypeCUD and write the following code in the class declaration node

  5. Override the description method and write the following code in it

  6. Override the isMatchingRule method and write the following code in it

  7. Override the isValidEventType method and write the following code in it

  8. Now the custom event has to be registered in the system. Go to AOT à Classes à EventType
  9. Open the eventTypeClassIdsHook method and write the following code in it

  10. Now Generate Incremental CIL to update the .NET libraries
  11. The custom event has been created. To test the event, go to Product information management à Common à Released products
  12. Select any record and click on the Edit button in the Maintain button group
  13. Navigate to the Sell fast tab and right click on the Price quantity field in the Base sales price group
  14. Select Create alert rule
  15. In the Create alert rule dialog, select the fields as shown in figure below and press OK
  16. The Alert rule has been created
  17. Now change the Price quantity to 0. A notification will pop-up on the bottom right most corner of Dynamics AX
  18. Note: Make sure the batch job Change based alerts is running. It can be configured from System administration à Periodic à Alertsà Change based alerts
  19. Clicking on the pop-up will open the details of the event
  20. The Notification list form can also be viewed from the notification’s button on the bottom status bar

No comments:

Post a Comment