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

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
    237,789 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

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 663 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 348 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans