Quick Tip: Getting Command Based Menus working in Dexterity

David Meego - Click for blog homepageIn the last couple of weeks, I have had a few cases where Dexterity command based menus for addon products no longer showed in Microsoft Dynamics GP 2010 after Service Pack 3 was installed.

In each of the cases, a review of the menu creation procedures identified that the code was actually incorrect. Once the code was fixed to use the correct dictionary numbers for the AddCommandToMenu() function, the menus worked perfectly.

The change in behaviour was caused by the fixing of an issue with the Dexterity Function Library command Command_GetTag() and its handling of dictionary IDs. If the menu creation code was written correctly, this fix would not cause any problems. Only incorrectly written code that previously worked, would no longer work.

 

Below are some rules for the dictionary numbers to use:

  • When referencing a command in a command form that is part of the core Dynamics.dic, make sure that the constant DYNAMICS is used for the dictionary number. 
     
  • When referencing a command in a command form that has been added as a 3rd party resource, use the function Runtime_GetCurrentProductID() for all dictionary numbers.

 

For example:

                Seq = 0;
                Status = AddCommandToMenu(DYNAMICS,
                     resourceid(form Command_System),
                     resourceid(command CL_Cards of form Command_System),
                     Seq,
                     MBS_DICT,
                     resourceid(form MBS_Commands),
                     resourceid(command MBS_Setup of form MBS_Commands),
                     true,
                     LoadMode);
                if Status <> OKAY then
                     error "Could not add command Menu MBS_Setup.";
                end if;

                Seq = 0;
                Status = AddCommandToMenu(DYNAMICS,
                     resourceid(form MBS_Commands),
                     resourceid(command MBS_Setup of form MBS_Commands),
                     Seq,
                     MBS_DICT,
                     resourceid(form MBS_Commands),
                     resourceid(command MBS_Install of form MBS_Commands),
                     true,
                     LoadMode);
                if Status <> OKAY then
                     error "Could not add command MBS_Install.";
                end if;

should be

                Seq = 0;
                Status = AddCommandToMenu(DYNAMICS,
                     resourceid(form Command_System),
                     resourceid(command CL_Cards of form Command_System),
                     Seq,
                     Runtime_GetCurrentProductID(),
                     resourceid(form MBS_Commands),
                     resourceid(command MBS_Setup of form MBS_Commands),
                     true,
                     LoadMode);
                if Status <> OKAY then
                     error "Could not add command Menu MBS_Setup.";
                end if;

                Seq = 0;
                Status = AddCommandToMenu(Runtime_GetCurrentProductID(),
                     resourceid(form MBS_Commands),
                     resourceid(command MBS_Setup of form MBS_Commands),
                     Seq,
                     Runtime_GetCurrentProductID(),
                     resourceid(form MBS_Commands),
                     resourceid(command MBS_Install of form MBS_Commands),
                     true,
                     LoadMode);
                if Status <> OKAY then
                     error "Could not add command MBS_Install.";
                end if;

Note: Using Runtime_GetCurrentProductID(), or a variable/parameter based on Runtime_GetCurrentProductID(), instead of a fixed product ID constant is better as it works correctly for test mode as well as runtime mode. This is because Runtime_GetCurrentProductID() returns 0 when in test mode and the addon product's dictionary ID when in runtime mode.

Hope this helps

David