web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Subscribe delegate in multiple classes in Dynamics 365 for operations

(0) ShareShare
ReportReport
Posted on by

Hi,

My requirement is to subscribe same delegate in many classes depending upon the logic to be executed.

Say Class A, Class B. Is there any attribute which can be set in order to setup the execution sequence of the handler class's subscriptions. Class A's delegate subscription need to be executed first, followed by Class B's delegate subscription. 

In dynamics 365 wiki, they have mentioned like mentioned below. 

https://ax.help.dynamics.com/en/wiki/delegates-for-migration/

“There can be more than one handler per delegate. There is not a defined order in the processing of handler methods. If order is important, delegate handler pairs
should be chained together.”


If so, How to chain the delegates handlers? Or is there a way to specify the sequence in which the handlers will execute?

Thanks,

Elamathi. S

*This post is locked for comments

I have the same question (0)
  • André Arnaud de Calavon Profile Picture
    301,035 Super User 2025 Season 2 on at

    Hi Elamathi,

    Can you describe the situation where you have two points to interact and the execution order is important?

    Probably you need to create two separate delegates. To be able to say something more meaningful, it would be interested to know the full requirements.

  • Martin Dráb Profile Picture
    237,880 Most Valuable Professional on at

    Let the handler of Class A expose an event that Class B can subscribe to (= chaining), call Class B directly from Class A, or create a separate event handler that will call Class A and Class B in the required order.

  • Suggested answer
    Basheer17 Profile Picture
    2,720 on at

    Event handlers are static and doesn't return anything. Even if we write event handler in either ClassA, ClassB we will not be able to make use of instance members or methods declared in the respective classes.

    In my opinion instead writing event handlers in two separate classes, write it in any one of the class or create new event handler class, write the code in required sequence, in this way you need not worry about the sequence of execution of event handlers.

    Please correct me if your requirement is defferent.

  • Martin Dráb Profile Picture
    237,880 Most Valuable Professional on at

    Of course that static methods can use instance methods - all you need is to create an object or get it from somewhere, such as from a parameter or a service locator.

  • Basheer17 Profile Picture
    2,720 on at

    Thanks martin, calling instance methods using object reference is still possible by writing event handler in any of the classes. (by creating new/ getting from somewhere).

    What i meant was by writing the event handlers in ClassA, ClassB we can't call instance methods like this.ClassAmethod() or this.ClassBmethod() in event handlers.

  • Martin Dráb Profile Picture
    237,880 Most Valuable Professional on at

    Sure, you can't refer to the current instance ("this") from static methods - it's a property of all static methods; it doesn't matter if they're used as event handlers or not. I've just somehow missed how it's related to Elamathi's question.

  • Community Member Profile Picture
    on at

    Hi André ,

    I need to add new logic validation logic. In standard they had already added validations in a subscription method. I need to add extra validations.

    So, I am again subscribing the delegate in my own class (Without customizing the standard subscription method). For the same delegate, i need to add extra validations, since my new logic depends on this standard delegate only.

    Now there are two subscription methods, one in standard class, another in my own class. I need to set sequence for these subscription methods execution.

    Regards,

    Elamathi. S

  • Verified answer
    Basheer17 Profile Picture
    2,720 on at

    Hi Elamathi

    If the existing event handler is hookable, you can create a Pre/Post event handler for it according to your requirement.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans