Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Answered

Event Handlers with parameters

(0) ShareShare
ReportReport
Posted on by 65

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

  • DDMoore Profile Picture
    DDMoore 65 on at
    RE: Event Handlers with parameters

    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

  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 230,842 Most Valuable Professional on at
    RE: Event Handlers with parameters

    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.

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,965 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,842 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans