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
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
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.
André Arnaud de Cal...
291,965
Super User 2025 Season 1
Martin Dráb
230,842
Most Valuable Professional
nmaenpaa
101,156