Hi everyone,
I’m looking for some clarification regarding the lifecycle of event handlers in M3 H5/Smart Office scripts.
Standard practice—and the Lawson Smart Office Developers Guide—suggests attaching validation logic using the following pattern:
C#
controller.add_Requesting(OnRequesting);
controller.add_Requested(OnRequested);
Inside OnRequesting, we perform our validation and set e.Cancel = true; if necessary. Then, inside OnRequested, we unregister both handlers to clean up:
C#
this.controller.remove_Requesting(OnRequesting);
this.controller.remove_Requested(OnRequested);
The Issue:It appears that triggers like F5 (Refresh) or F4 (Browse/Look-up) also fire the OnRequested event. Consequently, the handlers are removed prematurely. If a user performs a look-up and then tries to submit the form, the validation script no longer runs, allowing invalid data to be processed.
The Question:Is it actually necessary to manually remove these handlers? Does the M3 controller automatically dispose of these bindings when the window (panel) is closed?
I’m considering removing the remove_ logic entirely to ensure the validation remains active throughout the entire session of the panel, but I want to ensure this won't lead to memory leaks or unexpected side effects.
Has anyone else encountered this or changed their standard template because of this behavior?