axaptamicrosoft-dynamicsdynamics-ax-2012dynamics-ax-2009ax

Get caller of menuitem in global menu


I am calling a class through a menuItem in GlobalToolsMenu. The caller of my args is always null altough it is called from a form.

Is there a way to transmit the form as caller?


Solution

  • When you are opening a menu item from GlobalToolsMenu it isn't associated with the current form, it works as if you are trying to open a menu item from an independent menu. If you need to get access from the called class to the current form you need to use some workaround.

    E.g. you can try calling WinAPI::getForegroundWindow() from your class to retrieve a handle to the foreground window (the AX form with which the user is currently working). Having the handle, you need to find a corresponding FormRun object. For that purpose you can try customizing \Classes\SysSetupFormRun\init to keep a map with relations between form handles and the FormRun objects in infolog.globalCache(). Then you can use that cached map in your class to get the FromRun object from the retrieved handle.