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
- Microsoft Dynamics AX 2012
- 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:
- OriginalValue – The old value of the field
- CurrentValue – The current/new value of the field
- xValue – It is the event parameter, or the value to be monitored
-
TypeTrigger – It is an enum that determines what caused the event to occur
The most important methods of EventType class are as follows:
- description – This method defines the label of the event and therefore must be implemented
- isMatchingRule – This defines the condition whether the rule matches the event condition or not
- 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
- 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
- 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
- First of all create a new class. Open AOT àClasses
-
Right Click on Classes, choose New Class, and name it EventTypeIsZero
- Open the class declaration by right clicking on it and select View Code
-
Extend the newly created class with EventTypeCUD and write the following code in the class declaration node
-
Override the description method and write the following code in it
-
Override the isMatchingRule method and write the following code in it
-
Override the isValidEventType method and write the following code in it
- Now the custom event has to be registered in the system. Go to AOT à Classes à EventType
-
Open the eventTypeClassIdsHook method and write the following code in it
- Now Generate Incremental CIL to update the .NET libraries
- The custom event has been created. To test the event, go to Product information management à Common à Released products
- Select any record and click on the Edit button in the Maintain button group
- Navigate to the Sell fast tab and right click on the Price quantity field in the Base sales price group
- Select Create alert rule
- In the Create alert rule dialog, select the fields as shown in figure below and press OK
- The Alert rule has been created
-
Now change the Price quantity to 0. A notification will pop-up on the bottom right most corner of Dynamics AX
Note: Make sure the batch job Change based alerts is running. It can be configured from System administration à Periodic à Alertsà Change based alerts
- Clicking on the pop-up will open the details of the event
- The Notification list form can also be viewed from the notification’s button on the bottom status bar
No comments:
Post a Comment