Microsoft Dynamics AX This document describes the concept of events and how they can be used in Microsoft Dynamics AX.

Similar documents
January to April Upgrade Guide. Microsoft Dynamics AX for Retail

Content Development Reference. Including resources for publishing content on the Help Server

Design Insights Enhanced Cue Functionality

Global Address Book. Microsoft Dynamics AX White Paper

Country-specific update for Belgium

CRM Insights. User s Guide

WORKFLOW. Microsoft Dynamics AX. Integration of workflow capabilities into journals

Mapping the LedgerTrans Table to General Journal Tables

Microsoft Dynamics GP. Single Account Plan

Using the refactored formletter framework

02 Features of C#, Part 1. Jerry Nixon Microsoft Developer Evangelist Daren May President & Co-founder, Crank211

User Scripting April 14, 2018

Microsoft Dynamics GP. Multilingual Checks

Microsoft Dynamics GP. Inventory Kardex

Customize. Building a Customer Portal Using Business Portal. Microsoft Dynamics GP. White Paper

COPYRIGHT Wavextend B.V. All rights reserved. Calculation Framework user guide, Basic configuration for version

System Requirements for Microsoft Dynamics AX Microsoft Corporation Published: April 2011 This content is preliminary and is subject to change.

UPGRADING DEVELOPMENT SKILLS

Management Reporter Integration Guide for Microsoft Dynamics AX

Microsoft Dynamics GP. Purchase Vouchers

Microsoft Dynamics GP. Inventory Kardex

Extending BPEL with transitions that can loop

Microsoft Dynamics GP. RapidStart Services

Data Leakage Prevention. - Protection of Outbound Communication -

Microsoft Dynamics AX 2012 Installation Guide

Ten Things to Know Before Deploying Active Directory. written by Dmitry Sotnikov. White Paper

Migrate from Microsoft Dynamics CRM Online to Microsoft Dynamics CRM (on-premises) Applies to: Microsoft Dynamics CRM Online 2015 Update 1

Marketing List Manager 2011

Data Governance Data Usage Labeling and Enforcement in Adobe Experience Platform

LexisNexis Dossier Suite User Guide

[MS-SSP]: Intellectual Property Rights Notice for Open Specifications Documentation

Microsoft Dynamics GP. Working With Configurations Release 10.0

AT&T Business Voice Mail. Comprehensive Messaging Solution

Microsoft Dynamics GP. Inflation Adjustment

Data Governance: Data Usage Labeling and Enforcement in Adobe Cloud Platform

Using Threat Analytics to Protect Privileged Access and Prevent Breaches

Microsoft Dynamics GP. Localization Chile

Deploying enterprise applications on Dell Hybrid Cloud System for Microsoft Cloud Platform System Standard

Oracle Taleo Cloud for Midsize (Taleo Business Edition) Release 17B2. What s New

[MC-SMP]: Session Multiplex Protocol. Intellectual Property Rights Notice for Open Specifications Documentation

Class object initialization block destructor Class object

Extending Microsoft Dynamics AX 2009 Default Cubes for Analytics across Virtual Company Accounts

COMP322 - Introduction to C++

Paycode Mass Update 2013

Case Management Implementation Guide

use attributes (); # optional, to get subroutine declarations = attributes::get(\&foo);

Enterprise Instant Messenger User Guide Version

Building Web Sites Using the EPiServer Content Framework

Understanding Events in C#

Microsoft Dynamics AX RunBase Patterns

ZENworks Reporting System Reference. January 2017

EVENT-DRIVEN PROGRAMMING

UMD: UTAH MASTER DIRECTORY

Dynamics 365. for Finance and Operations, Enterprise edition (onpremises) system requirements

arxiv: v1 [cs.se] 17 Aug 2016

edocument for Italy - SAP Cloud Platform Integration Guide

GDPdU setup. Microsoft Dynamics AX White Paper

x10data Smart Client 6.5 for Windows Mobile Installation Guide

WORKGROUP MANAGER S GUIDE

Microsoft Dynamics AX 2012 Upgrade Guide. Microsoft Corporation Published: August 2011

Business Requirements Document (BRD) Template

Entitlement Management Implementation Guide

LightSpeed 5 Upgrade Guide

Oracle. Financials Cloud Implementing Subledger Accounting. Release 12. This guide also applies to on-premises implementations

Exception Handling Generics. Amit Gupta

Programming Languages Third Edition. Chapter 9 Control I Expressions and Statements

Assertions, pre/postconditions

Microsoft Dynamics GP. Analytical Accounting

Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.

Implementing and Supporting Windows Intune

Reference Library in Compliance 360 Version 2018

Package and Distribute Your Apps

Oracle. Applications Cloud Using Functional Setup Manager. Release 13 (update 18A)

Optimize postage savings. Expedite mail delivery. Pitney Bowes helps you make your mailstream more efficient.

Exception Handling. Sometimes when the computer tries to execute a statement something goes wrong:

Exception Handling. Run-time Errors. Methods Failure. Sometimes when the computer tries to execute a statement something goes wrong:

Oracle Cloud Using the Microsoft Adapter. Release 17.3

BPMN Getting Started Guide

VIEWER LICENSE GUIDE FOR SERVICEPOINT 5X

KwikTag v4.5.1 Release Notes

Getting Started with Cisco Pulse

Advanced BPEL. Variable initialization. Scope. BPEL - Java Mapping. Variable Properties

This slide is relevant to providing either a single three hour training session or explaining how a series of shorter sessions focused on per chapter

NAMESPACES IN C++ You can refer the Programming with ANSI C++ by Bhushan Trivedi for Understanding Namespaces Better(Chapter 14)

Oracle Cloud Using the Oracle Advanced Queuing (AQ) Adapter. Release 17.3

Exception-Handling Overview

1 Passageways Consulting: Employee Recognition

INNOVATE. Creating a Windows. service that uses Microsoft Dynamics GP econnect to integrate data. Microsoft Dynamics GP. Article

Avaya Client Applications Configurator User Guide

SaxoTraderPRO Intro guide

Getting Started with. InSpiredByYou.com COPYRIGHT STUDIOPLUS SOFTWARE, LLC ALL RIGHTS RESERVED

Microsoft Dynamics AX. Lifecycle Services: Operate Phase. Last Updated: June 2014 AX 2012 R3 / Version 1.0.0

Microsoft Dynamics GP Professional Services Tools Library

How to Write Effective Use Cases? Written Date : January 27, 2016

Centrify for Dropbox Deployment Guide

MMS DATA SUBSCRIPTION SERVICES USER INTERFACE GUIDE

Oracle Cloud Using the Trello Adapter. Release 17.3

COMP322 - Introduction to C++ Lecture 09 - Inheritance continued

Siebel Project and Resource Management Administration Guide. Siebel Innovation Pack 2013 Version 8.1/8.2 September 2013

SYMANTEC: SECURITY ADVISORY SERVICES. Symantec Security Advisory Services The World Leader in Information Security

Transcription:

Microsoft Dynamics AX 2012 Eventing White Paper This document describes the concept of events and how they can be used in Microsoft Dynamics AX. Date: January 2011 http://microsoft.com/dynamics/ax Author: Peter Villadsen, Senior Program Manager for X++ language Send suggestions and comments about this document to adocs@microsoft.com. Please include the title with your feedback.

Table of Contents Overview... 3 The nature of events... 3 Terminology... 4 Coded events... 4 Automatic events... 5 Method call before and after events... 5 Event handlers... 6 Adding handlers in the AOT... 6 Adding handlers in code... 6 Tips for events... 7 Do... 7 Don t... 7 2

Overview Microsoft Dynamics AX is rarely used by customers "out of the box." Each customer has a set of requirements to implement in the product. This has led to creation of an ecosystem of partners that customize the product to fit individual customers. The complexity of the customization process translates into cost for the customer. Currently, partners invest significant time in browsing and understanding the source code that is shipped by Microsoft. When the need for a customization is identified, the partner typically modifies the code in the customer's layer. The runtime engine ensures that the customization takes effect. A problem with the existing customization model is that customizations can be broken when Microsoft restructures code in a lower layer of the product, when a newer version is released. Fixing earlier customizations of the next version upgrade can be expensive for partners. The use of events has the potential to lower the cost of creating and upgrading customizations. Developers who create code that is often customized by others should create events in places where customizations typically occur. Then developers who customize the original functionality in another layer can subscribe to an event. When the customized functionality is tied to an event, then the underlying application code can then be rewritten and have little impact on the customization, as long as the same events are raised in the same sequence from one version to the next. The nature of events Object oriented programming paradigms often map easily to the problem domains that that they attempt to model. For example, classes are entities that typically represent a type of thing in real life, and the names chosen for classes are typically nouns like Accounts, People, and Customers. Methods are used to make changes to objects, and the names chosen for methods are then typically verbs that specify what operation is done on the objects, like Deposit, Hire, and Invoice. An event can be said to represent something that happens within an object. Applicable event names are verbs in the past tense, like Deposited, Hired, and Invoiced. Events are a simple and powerful concept. We encounter events all the time in our daily lives: The phone rings, an email message arrives, a computer breaks down because coffee is spilled on it, or you win the lottery. Some events are expected, but some are not. Many events happen all around us all the time and some are outside of the scope of our interest while some require us to take some sort of action. Events can be used to support the following programming paradigms: Observation: Events can be used to look for exceptional behavior and generate alerts when such behavior occurs. An example of this type of event is regulation compliance systems. For example, if more than a designated amount of money is transferred from one account to another, the system triggers a workflow that solicits acceptance of the transaction. Information dissemination: Events can deliver the right information to the right consumers at the right time. Information dissemination is supported by publishing an event to anyone wishing to react to it. Decoupling: Events produced by one part of the application can be consumed by a completely different part of the application. There is no need for the producer to be aware of the consumers, nor do the consumers need to know details about the producer. One producer's event can be acted upon by any number of consumers. Conversely, consumers can act upon any number of events from many different producers. 3

Terminology We modeled the concept of events in Microsoft Dynamics AX 2012 on.net eventing concepts. The following table lists the terms in Microsoft Dynamics AX 2012 related to events. Term Producer Definition The producer is the logic that contains the code that causes a change. It is an entity that emits events. Consumer The consumer is the application code that represents an interest in being notified when a specific event occurs. It is an entity that receives events. Event An event is a representation of a change having happened in the producer. Event Payload The event payload is the information that the event carries with it. When a person is hired, for example, the payload might include the employee's name and date of birth. Delegate A delegate is the definition of the information passed from the producer to the consumer when an event takes place. Coded events In X++, you can add delegates as members of a class. The syntax for defining a delegate is the same as the syntax used for defining a method, except that: The "delegate" keyword is used. Neither "public" nor any other accessibility specifier is allowed. The return type must be "void." The body must be empty; that is, it can contain neither declarations nor statements. For example, a delegate for an event that is raised when a person is hired could be expressed like this: delegate void hired(str name, UtcDateTime startingdate) Figure 1 illustrates a class called EventTest that includes one delegate called MyDelegate that accepts a string and an integer. Note The lightning icon indicates that this is a delegate and not an X++ method. 4

Figure 1: Application Object Tree (AOT) showing a class with an event When the application code needs to signal that a new person has been hired, it uses the delegate as a method call, supplying the event payload as parameters, as shown below: while select * from Employees where hireddate == today this.hired(employees.name, employees.firstworkingday); The parameters defined in the parameter profile can be any type allowed in X++. In particular, it is useful to pass an object instance, and to have the handlers modify the state of the object. In this way, the publisher can solicit values from the subscribers. Event handlers are run within the caller's transaction context. Subscribers can be added to the event in one of two ways: in the AOT or in X++ code. Automatic events Automatic events are events that are triggered by the environment as the result of something happening. Currently, a developer can indicate that an event is triggered when a method is called, as described below. Method call before and after events Pre and Post are predefined events that occur when methods are called. The pre-event handlers are called before the execution of the designated method, and the post-event handlers are called after the method call has ended. It may be a useful mental model to understand this as augmenting the existing method with methods called before and after the normal body, as shown in Table 1. Not having any event handlers for a particular method leaves the method intact. Therefore, there is no overhead incurred for methods that do not have any pre or post handlers assigned to them. The example in Table 1 also demonstrates that if an exception is thrown in any of the pre-event handlers, neither the remaining handlers nor the method itself is invoked. If a method that has preevent and/or post-event handlers throws an exception, the remaining post-event handlers are not invoked. If an exception is thrown in a post-event handler, the remaining handlers are not called. In any case, the exception propagates back to the caller as normal. Method before adding handlers void MyMethod (int i) Method Body Method after adding handlers void MyMethod (int i) PreHandler1(i); PreHandler2(i); Table 1: Methods with and without handlers Method Body PostHandler1(i); PostHandler2(i); Each of the pre-event handlers can access the original values of the parameters and modify them as required. The post-event handlers can modify the return value of the called method. 5

Event handlers Event handlers are the methods that are called when the delegate is called, either directly through code (for the coded events) or from the environment (in the modeled events). The relationship between the delegate and the handlers can be maintained in the code or in the Application Object Tree (AOT). Adding handlers in the AOT A developer must identify a static method to handle the event on the delegate. Only static methods can be used in this context. Event handlers can be added to the delegate by simply dragging the event handler to the delegate node that represents the event to be handled. The handler can be removed using the Delete menu item available for any node in the AOT. Figure 2 shows an event handler that has subscribed to an event: Figure 2: X++ Event handler added to MyDelegate The property sheet for an individual event handler shows the class and the method to call when the event occurs. The handler can be implemented either in managed code or in X++. Adding handlers in code It is possible to add and remove event handlers to events by using special X++ syntax, as shown below. The delegate name appears on the left side of the += operator. On the right hand side the keyword event handler is given, along with the qualified name of the handler to add. The compiler will check that the parameter profiles of the delegate and the handler match. private void AddStaticHandler() this.mydelegate += eventhandler (Subscriber::MyHandler); 6

The qualified name above uses the :: syntax to separate the type name and the delegate to designate that the handler is static. If a method on a particular object instance should be called, the dot character may be used instead of ::, as illustrated in the following snippet: private void AddInstanceHandler() Subscriber s = new Subscriber(); this.mydelegate += eventhandler (s.instancehandler); Removing the handler from a delegate is accomplished by using the -= operator instead of the += operator. Tips for events The following list summarizes DOs and DON'Ts to consider when working with events. Do Define events for things that programmers who are customizing the behavior of the system should react to. You should identify natural customization points and use events to publish the relevant information to subscribers. Maintain the semantics implied by the event from one version to the next. Part of the usefulness of events comes from the preservation of the semantics of the events. Once an interface has been defined, third parties will be able to leave their existing code unmodified if the semantics are left unchanged (even though the implementation behind might be modified). Document the events that you create well, for the sake of the people doing customization later. Favor defining events over using pre and post events on methods. Events are strong interfaces, while methods are an implementation artifact: A method's responsibilities and parameters may change over time, and they may disappear altogether as the developer sees fit. Don t Do not try to raise an event from outside the class in which the event is defined. The X++ compiler disallows raising events from outside the class by design. Do not make customizations that rely on the order in which event handlers are executed. No guarantees are made by the runtime environment about the order in which the event handlers are called. 7

Microsoft Dynamics is a line of integrated, adaptable business management solutions that enables you and your people to make business decisions with greater confidence. Microsoft Dynamics works like and with familiar Microsoft software, automating and streamlining financial, customer relationship and supply chain processes in a way that helps you drive business success. U.S. and Canada Toll Free 1-888-477-7989 Worldwide +1-701-281-6500 www.microsoft.com/dynamics This document is provided as-is. Information and views expressed in this document, including URL and other Internet Web site references, may change without notice. You bear the risk of using it. Some examples depicted herein are provided for illustration only and are fictitious. No real association or connection is intended or should be inferred. This document does not provide you with any legal rights to any intellectual property in any Microsoft product. You may copy and use this document for your internal, reference purposes. You may modify this document for your internal, reference purposes. 2011 Microsoft Corporation. All rights reserved. Microsoft, Microsoft Dynamics, and the Microsoft Dynamics logo are trademarks of the Microsoft group of companies. All other trademarks are property of their respective owners. 8