Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login




Remember Me
Forgot Password?
Join Us!

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Donate Today!

Do you enjoy these
technical forums?
Donate Today! Click Here

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Jobs from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

dcfaq (MIS) (OP)
7 Sep 12 17:37
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.
Borvik (Programmer)
10 Sep 12 10:22
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 --> name=Your_OpenCommandForms_POST

open form Style_Eyes_Main_Menu; 

CODE --> name=Your_CloseCommandForms_POST

close form Style_Eyes_Main_Menu; 

I hope this helps.
dcfaq (MIS) (OP)
10 Sep 12 11:25
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?
Borvik (Programmer)
10 Sep 12 11:57
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?
dcfaq (MIS) (OP)
10 Sep 12 14:44

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.
Borvik (Programmer)
11 Sep 12 8:33
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); 
dcfaq (MIS) (OP)
11 Sep 12 15:15
I have the Create DefaultsMenuStructure and OpenCommandForms all in my Startup procedure.

Do I take both of them out the startup script?
Borvik (Programmer)
11 Sep 12 15:40
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 --> name=Startup

{ 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 --> name=My_OpenCommandForms_POST

open form Style_Eyes_Main_Menu; 

CODE --> name=My_CloseCommandForms_POST

close form Style_Eyes_Main_Menu; 

CODE --> name=My_CreateMenuItems

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; 
dcfaq (MIS) (OP)
11 Sep 12 18:31
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.
Borvik (Programmer)
12 Sep 12 8:45
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.
dcfaq (MIS) (OP)
12 Sep 12 17:14
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;



Borvik (Programmer)
13 Sep 12 8:49
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.
dcfaq (MIS) (OP)
13 Sep 12 16:21
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);

Borvik (Programmer)
13 Sep 12 16:32
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.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close