Dynamics AX
  RSS Feed  LinkedIn  Twitter
Want to turn you're data into a true asset? Ready to break free from the report factory?
Ready to gain true insights that are action focused for truly data informed decisions?
Want to do all of this across mutliple companies, instances of Dynamics and your other investments?
Hillstar Business Intelligence is the answer then! (www.HillstarBI.com)

Hillstar Business Intelligence for Microsoft Dynamics AX and NAV on Mobile, Desktop, Tablet


Let us prove to you how we can take the complexity out of the schema and truly enable users to answer the needed questions to run your business! Visit Hillstar Business Solutions at: www.HillstarBI.com

Wednesday, June 29, 2011

Microsoft Dynamics AX 2012 Eventing - a look with X++



This week, I wanted to take sometime and actually dive into Microsoft Dynamics AX 2012 ability, within X++ to make use of Eventing!

Now I wrote about this, as an introduction to the idea, at the start of this year, here: Microsoft Dynamics AX 2012 and Eventing

This gave a good overview of the idea of eventing with Dynamics AX 2012, and gave some of the examples with Pre, Post and Custom Raised Events in mid stream of code.

With that in mind, and for reference, lets take this now a step further, and look at some real X++ code, objects, elements, make up, to help sink this home.



For my example, I'm actually doing straight X++, with no relation to any real world application yet. The idea is to understand what the mechanics are, and then from there apply those in design and in development as needed.

You will notice, in the above project, I have a few classes, called Apples & ApplePicker. I figured, I would make this a little bit more fun, than the standard hello world!

So lets take some time, to examine the Apples class within my project.



Here we see the class declaration, in which I have two variables I'm making use of. A Set, called appleBin and an int called apple. This is setting up, for later use, within the business logic of my Apples class.

Next we move forward to the New method of the Apples class.



With it, we see that I'm setting the variables that we saw in the class declaration, to initialize these variables, for the Set and int types.

Moving forward from there, we go to the next method, called growApple(). This is where some of the fun starts.



Here we see I'm taking the init apple, and adding one to it with the ++; call. Next we move to actually adding an "apple" to our appleBin set, with the int of apple as part of the key.

Moving from there, we see a final, what looks to be a method call, that is the following.:

"this.appleGrew(apple);"

In looking at this, it would seem as if this was a normal method, and it kinda of behaves as such, however this is not a method, but a delegate I created. We can get a peak, inside the delegate I created, for the Apples class, with the following screen shot.



Notice, that this blank actually, and not doing anything. Its truly a delegate, and looking at this, within the project, we will see that it appears differently, that the rest of the methods within the class.



You can create delegates within the AOT space of a given element, as we see on the Apples class in the above image. You do this, as if you were creating a new method.

What you should also notice, is the fact that below it, we have an event handler subscriber that we have created in the same fashion. These can be created within code as well, which for now we will shelve and come back to in a later post.

Diving deeper into the event handler subscription element, we can see that it has a property page, that allows us to take and set the class, type of, being X++ or Managed, and then the method to call.



Based on this setup for the event handler subscription element, we can then see it's calling a static method, called pickApple from the ApplePicker class.



Now it's very important to point out, that all event handler subscription elements, must be static methods. These are the only types allowed, for create such an event handler subscriber, or event listener.

So, what this is doing then, is when the Apples.growApple() is called, within it, via X++ code, we call to a delegate, of Apples.appledGrew(). This delegate, has a event handler subscription setup, for the ApplePicker.pickApple() method.

Lets now take a look inside that static method, which represents our event subscriber, called pickApple().



As you can see from the method, we are taking a parameter of int appleId, which happens to be the exact method signature of the delegate that is firing this event handler. This method, simply takes and calls to the info log, claiming that whatever the id value, is that apple has now been picked!

Seeing this in action, as part of this class, I have a job, with the following contents.



In here we see a simple job, that takes and creates a new instance of the Apples class, and does a for loop, for 10 iterations, of growing apples. Since our delegate will be called, after an apple is added to he Set, then we see a message similar to the one below, which was fired each time, from the event handler pickApple().



Now moving beyond the mechanics of this process, this can then been applied in several instances of AX. Typically, in other languages, we see such event handlers, as when buttons are clicked, or just before or after a method is fired.

That is actually an option you can do, for any method, you can setup a pre or post event handler subscription for a given method, that will fire on the pre or post processing of another given method.

We can also bring this eventing to a functional level, for say when a Sales Order or greater than $10,000.00 is invoiced, an event is fired that automatically places an order for a pizza party, for the dept. :-)

A little elementary school humor there, but if you really start to think about how this can be used, then the power of such abilities with Microsoft Dynamics AX 2012, comes to life.

Whats more, as I briefly mentioned above, is that this can fire into X++ code, or Managed code. That means C# code, that maybe calls into some WCF service, that takes the given Sales Order over $10,000.00 invoiced, and the customer and products to a cloud based Analysis database? Or fires into a WCF service, that is running on Azure, that connects to a gift card program, to automatically order a $100.00 gift card, for the given sales rep.

I'm reaching, but I'm trying to stretch the thought process into not only can this be used in the reference of given technical needs, like button clicks, or specific method calls, but also, could be used to wrap functional, business workflow events.

For your reference, the following link can be used to get the XPO file, that represents the project in AX 2012.: EventingExample_Appls.xpo

Your download and use of this is under your own terms, there is no warranty of any such for the code. It is, as is, so use in a Development environment of AX 2012, to help complete the picture of what this post explains.

That's all for now, and has we move forward, I will come back to this topic, with examples of managed code, showing off the pre and post event handler calls, as well as getting into some real world examples.

Till next time!



"Visit the Dynamics AX Community Page today!"

Labels: , , , , , , , ,

Thursday, February 03, 2011

Microsoft Dynamics AX 2012 and Eventing

One of the great new development improvements for Microsoft Dynamics AX 2012, that was talked about and demoed at the DAXCONF11 was "eventing".

For most people, that have ever done any Object oriented development or programming, eventing is a concept that most familiar.

It's is a concept that is used to fire before, just before or just after a given method call takes place. These can also be design within the middle of a method as well, if a given peice of business logic within the middle of a method, make sense to tie an event too.

If you bring this to a more functional level, you can think of eventing as something that happens for a given object. So if you have PackingSlip and Invoice. These are functional concepts represented by technical objects. Classes, business logic, etc.

So when something happens, you can say a Sales Order was invoiced, or packing slip updated.

To help explain, take a look at the following diagram.:


As you can see, we have a basic workflow of functional concepts taking place. We see that the two main functional concepts are PackingSlip and Invoice.

With these two concepts we see two common "events" or a Pre-PackingSlip Update, and a Post-PackingSlip Update. The same is said for Invoice, in that we have a Pre-Invoiced and a Post-Invoiced. What we also see is a custom, Mid-Invoiced event as well.

From this, we see two events that are used to call into CSharp or Xpp business logic, when these events are fired.

One is Post-PackinSlip and the other from the Custom Mid-Invoice event. This, I hope gives a good construct and idea behind the purpose and use of eventing.

You have the ability to "raise" and event, depending on certain actions within business logic. These events, when raised, have listeners, that can then fire into either Xpp code, or CSharp (.Net) developed code.

Moving forward, events are meant to support the following development concepts.:
  • Observation

  • Information dissemintation

  • Decoupling

After getting into what eventing can offer a customer doing custom development, or an ISV offering vertical expertise, we can see how this can help with the pains of upgrading.

So with eventing and Microsoft Dynamics AX 2012, a new possible way to develop custom code for a customer, or as an ISV is offered that has all kinds of great benefits. Everyone that does any development in Microsoft Dynamics AX, that does not undestand eventing, needs to make a priority to understanding eventing.




The above are some great resources to help understand eventings, event, delegates, and technical uses of events from a .Net point of view.

This is very important, as Microsoft Dynamics AX 2012 eventing, is based on .Net Eventing Concepts. What you will see, when looking at eventing in Microsoft Dynamics AX 2012 is.:
  • Producer - business logic or entity that raises an event

  • Consumer - a event listener, or logic called when a specific event is fired

  • Event - the given event called or raised when a process takes place

  • Event Payload - data or information caried within a fired event, for the consumers use

  • Delegate - is defined as informatin that was passed from a producer to a listener or consumer when an event is raised


I hope that you enjoyed this deeper dive into eventing with Microsoft Dynamics AX 2012, and eventing concept. It's a great move, that allows all kinds of possibilities, that all of us .Net developers, who also develop in Xpp have been looking for!



Visit Hillstar Business Intelligence (www.HillstarBI.com) in order to truly unlock your data trapped in your Microsoft Dynamics investment. With our value driven business intelligence strategy Hillstar help you transform into a data informed company.


Check back soon, as my next topic will be Development in Microsoft Dynamics AX 2009 and 2012. Differences, what's new, what can be done now and in the future.

See you next time!

"Visit the Dynamics AX Community Page today!"

Labels: , , , , , , , , ,


Copyright 2005-2011, J. Brandon George - All rights Reserved