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. public
    EventTypeIsZero extends EventTypeCUD
    {
    }
    

     

  6. Override the description method and write the following code in it
  7. public EventTypeDescription description()
    {
    //label for the event
    return
    "is 0";
    }
    

     

  8. Override the isMatchingRule method and write the following code in it
  9. public
    boolean isMatchingRule()
    {
    return currentValue == 0;
    }
    

     

  10. Override the isValidEventType method and write the following code in it
  11. public
    boolean isValidEventType(Types _types)
    {
    switch(_types)
    {
    case Types::Integer:
    case Types::Real:
    return
    true;
    
    case Types::Int64:
    return !this.isSurrogateForeignKey() && !this.isDimensionField();
    
    default:
    return
    false;
    }
    
    return
    false;
    }
    

     

  12. Now the custom event has to be registered in the system. Go to AOT à Classes à EventType
  13. Open the eventTypeClassIdsHook method and write the following code in it
    protected
    static
    container eventTypeClassIdsHook()
    {
    return [[classNum(EventTypeIsZero),EventTypeTrigger::FieldChanged]];
    }
    

     

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

  23. Clicking on the pop-up will open the details of the event
  24. The Notification list form can also be viewed from the notification’s button on the bottom status bar

  • sanjay singh

    The correct return value in switch statement of method isValidEventType is below

    return !this.isSurrogateForeignKey() && !this.isDimensionField();

Questions?

Email [email protected] with any questions you have pertaining to this course.

Follow Dynamics 101



About D101 Academy

Dynamics101.com is a Rand Group Knowledge Center intended to provide our clients, and the Microsoft community, with on-demand training.

Should you require personalized support for your business, Rand Group offers a variety of Business Advantage support plans to fit your business' needs.

View Rand Group's Microsoft support options.

top
New CPE Accredited Courses Now Available for Dynamics AX, GP, and NAVEARN CREDITS TODAY