Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dexerity - Adding a new Menu Item

Status
Not open for further replies.

dcfaq

MIS
Feb 1, 2010
9
US
I'm trying to migrate some older customized forms from GP 6 to GP10 and having a problem getting the startup scrip to add a menu.

The original code was as follows:

local integer l_result.
local string l_translate.
{---------------------------------------------------------------
This form trigger enables the "Extras" menu when you display the Dynamics Customer Maintenance window.
----------------------------------------------------------------}
set l_result to Trigger_RegisterForm(form Cards_Financial_Palette,
"Study List Application", "", script Study_List_Setup_Window).
if l_result<>SY_NOERR then
warning "Form trigger registration failed.".
if l_result=LOCKED then
warning "This recrod has been locked".
else
warning "This error came from the Startup Script".
end if.
end if.​


Well that doesn’t work any longer in GP 10 because Trigger_RegisterForm no longer exists so I tried the following:


if AddMenuItems = true then
{-- Add the Lead Maintenance item to the Cards>>Sales submenu--}
{Add a separator, which is a built-in command}
Seq = 0;
Status = AddCommandToMenu(DYNAMICS,
resourceid(form Command_Sales),
resourceid(command CL_Sales_Cards of form Command_Sales),
Seq,
3334, {Custom Dic}
resourceid(form Style_Eyes_Main_Menu), {Custom Form}
resourceid(command cmdSeparator),
true,
LoadMode);

if Status <> OKAY then
error "Could not add separator item.";
end if;

Seq = 0;
Status = AddCommandToMenu(DYNAMICS,
resourceid(form Command_Sales),
resourceid(command CL_Sales_Cards of form Command_Sales),
Seq,
3334, { this is the ID of my Custom Dictionary}
resourceid(form Style_Eyes_Main_Menu), {Custom Form}
resourceid(command Form_Open of form Style_Eyes_Main_Menu),
true,
LoadMode);

if Status <> OKAY then
error "Could not add Main_Menu command CL_Sales_Cards. Status = " + str(Status) +" ";
end if;
end if;


When it runs I get the message “Could not add separator item”. And “Could not add Main_menu command CL_SALES_CARDS. Status = 1”.

Tried everything and out of ideas.

Any help would be appreciated.
 
Well, for the actual menu item it looks pretty much like what I have used - it could be a number of reasons why that isn't working.

As for the separator, for the CmdDictID, and CmdFormID you are using your own dictionary and form so unless you have the separator defined yourself that is most likely why that is not working as the separator is a built-in command.

Here is what I have used for the separator:
Code:
	Status = AddCommandToMenu(DYNAMICS,
		resourceid(form Command_Sales),
		resourceid(command CL_Sales_Cards of form Command_Sales),
		Seq,
		CMD_BUILTINCMD_DICTID, {**Notice the constant in use here**}
		CMD_BUILTINCMD_FORMID, {**Notice the constant in use here**}
		resourceid(command cmdSeparator),
		true,
		LoadMode);

If the form you have your commands on isn't open you could also run into trouble (though I don't know if it would effect the status of the AddCommandToMenu function).

I would recommend (and I believe it is the recommended way) to put the creation of the menu into its own script and have it triggered after CreateDefaultMenuStructure:
Code:
if Trigger_RegisterProcedure(script CreateDefaultMenuStructure, TRIGGER_AFTER_ORIGINAL, script YourMenuItemCreationScript) <> SY_NOERR then
    warning "Procedure trigger registration failed.";
end if;

Also the following is recommended to automatically open and close your command forms:
Code:
if Trigger_RegisterProcedure(script 'OpenCommandForms', TRIGGER_AFTER_ORIGINAL, script Your_OpenCommandForms_POST) <> SY_NOERR then
    warning "OpenCommandForms procedure trigger registration failed.";
end if;
if Trigger_RegisterProcedure(script 'CloseCommandForms', TRIGGER_AFTER_ORIGINAL, script Your_CloseCommandForms_POST) <> SY_NOERR then
    warning "CloseCommandForms procedure trigger registration failed.";
end if;
Were your respective scripts are:
Code:
open form Style_Eyes_Main_Menu;
Code:
close form Style_Eyes_Main_Menu;

I hope this helps.
 
Thanks for responding. A few questions.

Regarding the script:
if Trigger_RegisterProcedure(script CreateDefaultMenuStructure, TRIGGER_AFTER_ORIGINAL, script YourMenuItemCreationScript) <> SY_NOERR then
warning "Procedure trigger registration failed.";
end if;

The Script 'CreateDefaultMenuStrucutre' and 'Your_CloseCommandForms_POST'? Where is this script locaetd? Is it a Procedure script or one off of a form?
 
YourMenuItemCreationScript, Your_CloseCommandForms_POST, and Your_OpenCommandForms_POST are all scripts you would create as global Procedures.

As far as the CreateDefaultMenuStructure script, you are attaching to that script. This should be a script that already exists within GP as is OpenCommandForms, and CloseCommandForms. Using Trigger_RegisterProcedure you are attaching your scripts to the scripts GP actually uses so that all your scripts run at the appropriate times and in the appropriate order.

Does that clear things up?
 

OK, I think I’m getting close. I have in my startup script the following:


{-- A
dd the Lead Maintenance item to the Cards>>Sales submenu--}
{Add a separator, which is a built-in command}
Seq = 0;
Status = AddCommandToMenu(DYNAMICS,
resourceid(form Command_Sales),
resourceid(command CL_Sales_Cards of form Command_Sales),
Seq,
CMD_BUILTINCMD_DICTID, {**Notice the constant in use here**}
CMD_BUILTINCMD_FORMID, {**Notice the constant in use here**}
resourceid(command cmdSeparator),
true,
LoadMode);

if Trigger_RegisterProcedure(script CreateDefaultMenuStructure, TRIGGER_AFTER_ORIGINAL, script Open_Main_Menu) <> SY_NOERR then
warning "Procedure trigger registration failed.";
end if;

if Trigger_RegisterProcedure(script 'OpenCommandForms', TRIGGER_AFTER_ORIGINAL, script Open_Main_Menu) <> SY_NOERR then
warning "OpenCommandForms procedure trigger registration failed.";
end if;

if Trigger_RegisterProcedure(script 'CloseCommandForms', TRIGGER_AFTER_ORIGINAL, script Close_Main_Menu) <> SY_NOERR then
warning "CloseCommandForms procedure trigger registration failed.";
end if;​

I have a Procedure that has Open_Main_Menu and another for Close_Main_Menu.

When I open GP it opens my Main Menu and I am able to work with the main menu. So I at least have a main menu.

What I was hoping to do was to have a button on Sales >> Cards that I can select that would open the custom main menu when I need it? How do I get there?

Thanks again in advance.
 
Ok, the script you are attaching to CreateDefaultMenuStructure should be a separate script than the OpenCommandForms one.

That script should be the one that creates your menus:
Code:
{-- A
  dd the Lead Maintenance item to the Cards>>Sales submenu--}
  {Add a separator, which is a built-in command}
  Seq = 0;
  Status = AddCommandToMenu(DYNAMICS,
    resourceid(form Command_Sales),
    resourceid(command CL_Sales_Cards of form Command_Sales),
    Seq,
    CMD_BUILTINCMD_DICTID, {**Notice the constant in use here**}
    CMD_BUILTINCMD_FORMID, {**Notice the constant in use here**}
    resourceid(command cmdSeparator),
    true,
    LoadMode);
 
I have the Create DefaultsMenuStructure and OpenCommandForms all in my Startup procedure.

Do I take both of them out the startup script?
 
No that's fine. The Trigger_RegisterProcedure calls for these should be in the Startup procedure. The AddCommandToMenu calls should be in a separate script attached to the CreateDefaultMenuStructure procedure:

Code:
{ Create and show the menu items. }
if Trigger_RegisterProcedure(script CreateDefaultMenuStructure, TRIGGER_AFTER_ORIGINAL, script My_CreateMenuItems) <> SY_NOERR then
    warning "Procedure trigger registration failed.";
end if;
if Trigger_RegisterProcedure(script 'OpenCommandForms', TRIGGER_AFTER_ORIGINAL, script My_OpenCommandForms_POST) <> SY_NOERR then
    warning "OpenCommandForms procedure trigger registration failed.";
end if;
if Trigger_RegisterProcedure(script 'CloseCommandForms', TRIGGER_AFTER_ORIGINAL, script My_CloseCommandForms_POST) <> SY_NOERR then
    warning "CloseCommandForms procedure trigger registration failed.";
end if;

Code:
open form Style_Eyes_Main_Menu;

Code:
close form Style_Eyes_Main_Menu;

Code:
in integer LoadMode;
optional in boolean ShowProgress;

local CmdSequence Seq;
local integer Status;
local boolean AddMenuItems;
local integer Prod_ID;
Prod_ID = 3334; {Though you should register for one so it won't ever interfere with something you may purchase}

{Set the flag indicating that menu items should be added}
AddMenuItems = true;

if LoadMode = MENULOAD_TOTABLE then
    {Find out whether the menu items exist in the Menu Master table.}
    if MenusExistForProduct(Prod_ID) of form syMenuObj = true then
        {Do not need to add the menu items}
        AddMenuItems = false;
    end if;
end if;

if AddMenuItems = true then
    {Add a separator, which is a built-in command}
    Seq = 0;
    Status = AddCommandToMenu(DYNAMICS,
        resourceid(form Command_Sales),
        resourceid(command CL_Sales_Cards of form Command_Sales),
        Seq,
        CMD_BUILTINCMD_DICTID,
        CMD_BUILTINCMD_FORMID,
        resourceid(command cmdSeparator),
        true,
        LoadMode);

    if Status <> OKAY then
        error "Could not add separator item.";
    end if;

    Seq = 0;
    Status = AddCommandToMenu(DYNAMICS,
        resourceid(form Command_Sales),
        resourceid(command CL_Sales_Cards of form Command_Sales),
        Seq,
        Prod_ID, { this is the ID of my Custom Dictionary}
        resourceid(form Style_Eyes_Main_Menu), {Custom Form}
        resourceid(command Form_Open of form Style_Eyes_Main_Menu),
        true,
        LoadMode);

    if Status <> OKAY then 
        error "Could not add Main_Menu command CL_Sales_Cards. Status = " + str(Status) +" "; 
    end if;
end if;
 
Borvik

I create Startup,name=My_OpenCommandForms_POST,My_CloseCommandForms_POST and My_CreateMenuItems just as you have it above and it does work but not as I had planned.

When I open GP and unchunk the file it has my main menu on top of the existing GP menus. This is not a stand alone app, I need it to work with the existing GP app.

I'm trying to bet my menu 'Style_Eyes_Main_Menu' to appear in Sales >> Cards.

Right now its there but not where I perfer. Any way to get it there?

Thanks again.
 
As far as I can see from the posted code, it should be adding it to Cards >> Sales.

The first three parameters of AddCommandToMenu are what determine where the command will be added: DYNAMICS, form Command_Sales, and command CL_Sales_Cards of form Command_Sales.

Looking at the Integration Guide under Navigation >> "Menus in Microsoft Dynamics" I can see that those are indeed correct, and in fact there is an example in there that shows adding a command to this same menu.

Please ALSO check under Cards >> Sales to see if it doesn't exist in both places.
 
Just reviewed everything and I’m still not seeing why the menu opens on the startup but is not visiable under Sales >> Cards. Any ideas where I might look?

I'm assuming that it should appear at the bottom of the cards. I can see a new sperator line but not my entry I"m looking for.


Startup Procedure:
{ Create and show the menu items. }
if Trigger_RegisterProcedure(script CreateDefaultMenuStructure, TRIGGER_AFTER_ORIGINAL, script My_CreateMenuItems) <> SY_NOERR then
warning "Procedure trigger registration failed.";
end if;
if Trigger_RegisterProcedure(script 'OpenCommandForms', TRIGGER_AFTER_ORIGINAL, script My_OpenCommandForms_POST) <> SY_NOERR then
warning "OpenCommandForms procedure trigger registration failed.";
end if;
if Trigger_RegisterProcedure(script 'CloseCommandForms', TRIGGER_AFTER_ORIGINAL, script My_CloseCommandForms_POST) <> SY_NOERR then
warning "CloseCommandForms procedure trigger registration failed.";
end if;
My_OpenCommandForms_POST Procedure:

open form Style_Eyes_Main_Menu;



My_CloseCommandForms_POST Procedure:

close form Style_Eyes_Main_Menu;


My_CreateMenuItems Procedure:

in integer LoadMode;
optional in boolean ShowProgress;

local CmdSequence Seq;
local integer Status;
local boolean AddMenuItems;
local integer Prod_ID;
Prod_ID = 3334; {Though you should register for one so it won't ever interfere with something you may purchase}

{Set the flag indicating that menu items should be added}
AddMenuItems = true;

if LoadMode = MENULOAD_TOTABLE then
{Find out whether the menu items exist in the Menu Master table.}
if MenusExistForProduct(Prod_ID) of form syMenuObj = true then
{Do not need to add the menu items}
AddMenuItems = false;
end if;
end if;

if AddMenuItems = true then
{Add a separator, which is a built-in command}
Seq = 0;
Status = AddCommandToMenu(DYNAMICS,
resourceid(form Command_Sales),
resourceid(command CL_Sales_Cards of form Command_Sales),
Seq,
CMD_BUILTINCMD_DICTID,
CMD_BUILTINCMD_FORMID,
resourceid(command cmdSeparator),
true,
LoadMode);

if Status <> OKAY then
error "Could not add separator item.";
end if;

Seq = 0;
Status = AddCommandToMenu(DYNAMICS,
resourceid(form Command_Sales),
resourceid(command CL_Sales_Cards of form Command_Sales),
Seq,
Prod_ID, { this is the ID of my Custom Dictionary}
resourceid(form Style_Eyes_Main_Menu), {Custom Form}
resourceid(command Form_Open of form Style_Eyes_Main_Menu),
true,
LoadMode);

if Status <> OKAY then
error "Could not add Main_Menu command CL_Sales_Cards. Status = " + str(Status) +" ";
end if;
end if;



 
From a code standpoint, I'm not seeing anything inherently wrong with that code.

I'm guessing that if you comment out the code in My_CreateMenuItems that pertains to the menu item and not the separator it would disappear from the top menu, leaving only the separator in Cards >> Sales.

I wonder if it could be the way the Command and the Form that houses the command is setup.
 
I have a few more facts and a few questions that might be helpful in this problem.

Question:
I found that in the startup script this code is what opening up the main form on top of the exsting menu so what is the point of this code?

if Trigger_RegisterProcedure(script 'OpenCommandForms', TRIGGER_AFTER_ORIGINAL, script Your_OpenCommandForms_POST) <> SY_NOERR then
warning "OpenCommandForms procedure trigger registration failed.";
end if;


Also, I see that the following code adds a separator at the end of the Sales >> Cards. This line looks fine.

if AddMenuItems = true then
{Add a separator, which is a built-in command}
Seq = 0;
Status = AddCommandToMenu(DYNAMICS,
resourceid(form Command_Sales),
resourceid(command CL_Sales_Cards of form Command_Sales),
Seq,
CMD_BUILTINCMD_DICTID,
CMD_BUILTINCMD_FORMID,
resourceid(command cmdSeparator),
true,
LoadMode);


This code here is supposed to add an entry to the end of the Sales >> Cards after the separator that was added above to open up my menu. I see that the resouceID that is being added is form Style_Eyes_Main_Menu. I think the problem is here. This Form Style_Eyes_Main_Menu is a standard form with a few button's on it. I didn't think this would be a form but rather something other then a form. Am I on track on this?

Seq = 0;
Status = AddCommandToMenu(DYNAMICS,
resourceid(form Command_Sales),
resourceid(command CL_Sales_Cards of form Command_Sales),
Seq,
Prod_ID, { this is the ID of my Custom Dictionary}
resourceid(form Style_Eyes_Main_Menu), {Custom Form}
resourceid(command Form_Open of form Style_Eyes_Main_Menu),
true,
LoadMode);

 
Yes, you only need one script attached to OpenCommandForms (at least for the example we are working on here). Only keep the one you are actually using. One of this triggers IS necessary, as the form hosting the commands does need to be open for them to show up in the menu.

I think you are hitting the nail on the head with that last bit. This shouldn't be a standard form.

There should be a single window in it Name:Dummy, Title:~internal~, AutoOpen:False.
Then add your commands to it.
Don't forget to update to Form and command references in these scripts.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top