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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Event Handlers with parameters

(0) ShareShare
ReportReport
Posted on by 71

I'm trying to create an X method which will setup an event handler that is data-driven.   In other words data in a table will define which form, field and event will have an event handler created for it.  

Something like this, where the form name and field name are passed into a method

public static void CreateEventHandler(str formName, str fieldName)
    {
        [FormControlEventHandler(formControlStr(formName, fieldName), FormControlEventType::Clicked)]
        public static void Test_OnClickedEvent(FormControl sender, FormControlEventArgs e)
        {
            xFormRun formRunObjectr = sender.formRun();
        }
    }

Can run-time event handlers be created or are event handlers defined at compile time?

Thanks for any assistance.

Duane

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

    Your design is completely impossible. Attributes, such as FormControlEventHandlerAttribute, are defined at compile time, not at at runtime. You also can't create a static method nested in another method, and you don't decorate inner methods with attribute.

    You can subscribe event handlers to events, but not with FormControlEventHandlerAttribute. You need to use syntax like this:

    this.anEvent  = eventhandler(object.eventHandlerMethod);

    The handler may be either instance or static.

    You'll need think about a different design for your business requirement. If you want our help with it, explain the scenario to us.

  • DDMoore Profile Picture
    71 on at

    Thanks for the response.

    Currently we have predefined events on form button clicks.  On the button click our code will print a label.   We'd like to be able to allow a user to define these dynamically.  This way the user can define where in D365 F&O they want to produce a label.

    I was not surprised by your response saying that the event handlers are set at compile time and not runtime.   If the event handlers cannot be set at runtime, this approach will not work at all.

    Thanks for the response.

    Duane

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 514 Super User 2026 Season 1

#2
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 390

#3
Adis Profile Picture

Adis 266 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans