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 :
Finance | Project Operations, Human Resources, ...
Answered

Whether to use event handlers on custom forms

(0) ShareShare
ReportReport
Posted on by 1,215

Hi all,

Need some suggestion:

The requirement is, to execute some code on the click of a button on a custom form.
If we had a standard form, we would have had to write the code in a relevant event handler.
Since we have a custom form, the conundrum is whether to add a method to the buttons methods node, or
to create a helper class and add _OnClicked event handler and write the code there?

1. We no longer have server-client tiers.
2. Which is more manageable methods in custom forms or relevant event handlers.
3. To access global variables in events methods, parm methods are required.
4. To access any datasources or datasource records, additional cumbersome code needs to written.
5. In future, for any additional changes, all the events are to be checked.

Any suggestions are welcome!

With best regards,
Abhinay

I have the same question (0)
  • Verified answer
    Martin Dráb Profile Picture
    237,807 Most Valuable Professional on at

    You didn't mention the option that is usually the best - using a menu item button. This has many benefits, especially for reusability - you can easily call the logic from many places while defining all properties (such as the label) and security just once.

    If it's not suitable for a menu item button, it's easier to use clicked() than an event handler. But shouldn't put much code there - rather create a separate method and call this method from clicked(). It's for discoverability and reusability.

    But event handlers have their benefits too. For example, you can define a single handler method for events from multiple controls or forms.

  • Verified answer
    nmaenpaa Profile Picture
    101,160 Moderator on at

    I would not develop any event handlers or Chain of Command augmentations on my own objects. They are useful when extending someone else's code (Microsoft's or ISV's). Also it makes more difficult for others to extend your solution if you are already heavily using events around your own code. But if this is a CUS project (and not ISV) then that wouldn't have an impact.

  • Verified answer
    Joris dG Profile Picture
    17,775 on at

    As already mentioned I would avoid CoC and events on entirely custom forms for multiple reasons. The main one for me would be maintainability and readability.

    Also, to some of your points. Forms can implement interfaces. This can greatly improve how you interact with and code against a form.

  • Abhinay Tharwal Profile Picture
    1,215 on at

    Thank you Martin, Nikolaos and Joris for your valuable suggestions!

    goshoom I will consider the one method multiple controls' event handlers approach.

    Joris dG I will keep in mind about the interface approach.

    With best regards,

    Abhinay

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 > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 664 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 522 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 303 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans