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 75

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

  • Verified answer
    Martin Dráb Profile Picture
    240,972 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
    75 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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the August Top 10 Community Leaders

These are the community rock stars!

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

#1
Martin Dráb Profile Picture

Martin Dráb 555 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 484 Super User 2026 Season 2

#3
CU10121822-0 Profile Picture

CU10121822-0 378

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans