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

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Delegates for form methods in Dynamics 365

(0) ShareShare
ReportReport
Posted on by 185

Hi All,

I was wondering if we could create delegates for form methods. If we cannot create in forms then what would be alternative for the same? 

I have a piece of code that I need to overlayer in the form methods, it does not have any events to create event handlers for the method? 

What would be the best approach to avoid overlayering in such form methods?

*This post is locked for comments

I have the same question (0)
  • Mea_ Profile Picture
    60,284 on at
    RE: Delegates for form methods in Dynamics 365

    Hi Manjunath Ingalagi,

    You can create pre and post event handlers for public methods on a form. So why do you need a delegate ?

  • Manjunath Ingalagi Profile Picture
    185 on at
    RE: Delegates for form methods in Dynamics 365

    Hi ievgen Miroshnikov,

    For the method(xyz) which I have to write some custom piece of code, I cannot create a  pre or post event handlers, as it does not have the respective event for the method in which I am supposed to write my custom code. The alternative I thought of would be to create event handlers for all the methods which call this method(xyz),as they have the events for the respective methods. But the method(xyz) is not exactly called at the beginning or at the end of the code. So if I write a pre post event handler, I am not sure if it would be working as expected for some of the methods where method(xyz) is called.

  • Mea_ Profile Picture
    60,284 on at
    RE: Delegates for form methods in Dynamics 365

    Why do you need an event at all ? Just open form in a designer -> right click on a method you want to create event handler for -> "Copy event handler method" -> select pre or post. Then past code from clipboard to a class.

    Here is example of random method on salesTable from. 

    8130.Untitled.png

  • Manjunath Ingalagi Profile Picture
    185 on at
    RE: Delegates for form methods in Dynamics 365

    I am customizing in PurchTable form > PurchLine datasource > itemIdModified method. This does not have the event handlers.

    PurchTable.PNG

  • Suggested answer
    Mea_ Profile Picture
    60,284 on at
    RE: Delegates for form methods in Dynamics 365

    You cannot subscribe to form data source methods and obviously there is no events for them. The only thing you can do is to customize ( as I can see from screenshot it is already customized) this form and modify method directly. If you don't want to add too much code there you can create delegate(like in this blog post axrachit.blogspot.co.nz/.../using-x-delegates-in-new-dynamics-ax.html) and subscribe to it.

  • André Arnaud de Calavon Profile Picture
    299,149 Super User 2025 Season 2 on at
    RE: Delegates for form methods in Dynamics 365

    Hi Manjunath,

    Can you use the event OnModified of the PurchLine.ItemId field? This is called after the method OnModified which is calling the ItemIdModified method you want to interact with.

    2017_2D00_01_2D00_10_5F00_08_2D00_48_2D00_32.png

  • Manjunath Ingalagi Profile Picture
    185 on at
    RE: Delegates for form methods in Dynamics 365

    hi ievgen Miroshnikov,

    Actually I have been asked to keep minimal code on the standard form method and use event handler as much as possible, as we cannot use the event handlers for the datasource methods so I thought maybe we can try and use delegates, but I am not able to use it. I already tried with the link above. It seems like we cannot use the delegates in forms.

  • Manjunath Ingalagi Profile Picture
    185 on at
    RE: Delegates for form methods in Dynamics 365

    Hi André,

    As you suggested that is the alternative that I found which I was talking about in the above post. The itemIdModified method is called in modified method on the ItemId field in the PurchLine dataSource. So I was planning to write in the event handler for the ItemId modified method.

  • Verified answer
    Mea_ Profile Picture
    60,284 on at
    RE: Delegates for form methods in Dynamics 365

    Take a look at DimensionHierarchyDelegates class and it's usage. It has couple of delegates declared and they are invoked from DimensionFocus form.

    If you want to declare delegate on a form you need to declare it on the form level, not data source:

    0257.Untitled1.png

    0257.Untitled1.png

  • Manjunath Ingalagi Profile Picture
    185 on at
    RE: Delegates for form methods in Dynamics 365

    Hi ievgen Miroshnikov,

    It does allow in the form methods, but not in the DataSource methods? So would it ok if we create a delegate in the form methods and use it datasource methods? I think it should be fine rite?

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Community Member Profile Picture

Community Member 4

#2
Guy Terry Profile Picture

Guy Terry 2 Moderator

#2
Nayyar Siddiqi Profile Picture

Nayyar Siddiqi 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans