Toolbar creation procedure

To create a toolbar for your integrating application, you need to define a command list that will contain the toolbar items. You must also write a procedure that defines the toolbar. This procedure runs in response to a trigger you will add for the CreateDefaultCommandBars procedure in Microsoft Dynamics GP. You will also write a procedure that defines the commands that will appear on the toolbar. This procedure runs in response to a trigger you will add for the CreateDefaultCmdBarButtons procedure in Microsoft Dynamics GP.

Toolbar command list

Each toolbar displayed in Microsoft Dynamics GP has a command list defined that contains the items shown on the toolbar. You will create a command list (command resource) for your toolbar that will contain the items displayed by the toolbar. Define the toolbar command list on the command form that contains the other commands used for your integration.

For example, the sample integrating application defines the CL_IG_Sample_CMDBAR command on the Command_IG_Sample form. This command list will contain the commands displayed by the toolbar for the sample integration.

Registering the toolbar creation triggers

The following example shows the registration in the sample integrating application for the trigger that runs in response to the CreateDefaultCommandBars procedure in Microsoft Dynamics GP. When the trigger is activated, the IG_CreateToolbars procedure is run.

l_result = Trigger_RegisterProcedure(script CreateDefaultCommandBars, TRIGGER_AFTER_ORIGINAL, script IG_CreateToolbars);
if l_result <> SY_NOERR then
	warning "Procedure trigger registration failed.";
end if;

The following example shows the registration in the sample integrating application for the trigger that runs in response to the CreateDefaultCmdBarButtons procedure in Microsoft Dynamics GP. When the trigger is activated, the IG_CreateToolbarItems procedure is run.

l_result = Trigger_RegisterProcedure(script CreateDefaultCmdBarButtons, TRIGGER_AFTER_ORIGINAL, script IG_CreateToolbarItems);
if l_result <> SY_NOERR then
	warning "Procedure trigger registration failed.";
end if;

Trigger processing procedures

The following is the IG_CreateToolbars procedure for the sample integrating application. It runs in response to the trigger for the CreateDefaultCommandBars procedure. It uses the ExistsForUserID() function in Microsoft Dynamics GP to verify whether a toolbar has already been added for the default set. If one hasn’t, it uses the AddCommandBar() function to add the toolbar and clone it for each user.

local integer status;
local integer pos;

{Add command bar only if it doesn't exist for the user}
if ExistsForUserID("",
	IG_PROD_ID,
	resourceid(form Command_IG_Sample), 
	resourceid(command CL_IG_Sample_CMDBAR of form Command_IG_Sample)) of form syCmdBarObj = true then
	abort script;
end if;

{Add the toolbar and clone for each user who has toolbars}
pos = 0; {Place at the beginning of the row}
status = AddCommandBar("",
	IG_PROD_ID,
	resourceid(form Command_IG_Sample),
	resourceid(command CL_IG_Sample_CMDBAR of form Command_IG_Sample),
	true, {visibility}
	2, {row number}
	pos, {position}
	true) of form syCmdBarObj;

The following is the toolbar command creation procedure for the sample integrating application. It runs in response to the trigger for the CreateDefaultCmdBarButtons procedure. The trigger processing procedure uses the ButtonsExistForProduct() function to find whether commands have already been added to the toolbar. If they have not, it uses the AddCommandToCmdBar() function to add two items that will appear on the toolbar.

local integer status;
local integer Seq;

{Add default items to the toolbar if they don't already exist}
if ButtonsExistForProduct(IG_PROD_ID) of form syCmdBarBtnObj = true then
	abort script;
end if;

Seq = 1;
status = AddCommandToCmdBar(IG_PROD_ID,
	resourceid(form Command_IG_Sample),
	resourceid(command CL_IG_Sample_CMDBAR of form Command_IG_Sample),
	Seq,
	IG_PROD_ID,
	resourceid(form Command_IG_Sample),
	resourceid(command IG_Lead_Maintenance of form Command_IG_Sample),
	true, {available for all users}
	MENULOAD_TOTABLE);

increment Seq;
status = AddCommandToCmdBar(IG_PROD_ID,
	resourceid(form Command_IG_Sample),
	resourceid(command CL_IG_Sample_CMDBAR of form Command_IG_Sample),
	Seq,
	IG_PROD_ID,
	resourceid(form Command_IG_Sample),
	resourceid(command IG_Lead_Inquiry of form Command_IG_Sample),
	true, {available for all users}
	MENULOAD_TOTABLE);

Toolbar menu item

Access to toolbars is controlled through the Toolbars context menu that is accessed through the Layout menu. The Toolbars context menu can also be accessed by right-clicking in the toolbar area in Microsoft Dynamics GP. Add an entry to the Toolbars context menu for each toolbar you create to allow the user to hide or show it.

[spacer]

Create a command for the item to add to the Toolbars context menu, just as you would any other command for your integration. The Toolbars context menu is a built-in command defined by Dexterity. For example, the Toolbar_IGSample command (a script command) is defined in the Command_IG_Sample command form for sample integrating application. The command is added to the the Toolbars context menu to control access to the sample toolbar.

Typically, the menu item is added by the same procedure used to add the other menu items for your integraiton. For example, the following is a portion of the IG_CreateMenuItems procedure in the sample integration. It adds the command for the sample toolbar to the Toolbars context menu.

{Add the item to display the sample toolbar}
{Find the appropriate location of the Custom toolbar item}
Seq = FindCommandInMenu(CMD_BUILTINCMD_DICTID,
	CMD_BUILTINCMD_FORMID,
	resourceid(command cmdToolbarContextMenu),
	DYNAMICS,
	resourceid(form Command_System),
	resourceid(command Toolbar_Custom of form Command_System),
	LoadMode,
	"");

Status = AddCommandToMenu(CMD_BUILTINCMD_DICTID,
	CMD_BUILTINCMD_FORMID,
	resourceid(command cmdToolbarContextMenu),
	Seq,
	IG_PROD_ID,
	resourceid(form Command_IG_Sample),
	resourceid(command Toolbar_IGSample of form Command_IG_Sample),
	true,
	LoadMode);

The script attached to the command performs two actions when the item is chosen from the Toolbars context menu. It retrieves the tags for the menu item and the toolbar the command is controlling. It uses these tags to toggle the state of the toolbar and the check mark for the menu item. The following is the script for the Toolbar_IGSample command for the sample integration.

local integer nMenuTag, nCmdBarTag, nStatus;

nMenuTag = Command_GetTag(command Toolbar_IGSample);
nCmdBarTag = Command_GetTag(command CL_IG_Sample_CMDBAR);

nStatus = ToggleCommandBar(nMenuTag, nCmdBarTag) of form syCmdBarObj;

Toolbar menu state

When Microsoft Dynamics GP is started, it will automatically display the toolbars that the user had displayed when they last ran the application. Code for your integration must set the state of the toolbar menu item to be checked or unchecked, depending on whether the toolbar is currently displayed. You will use a trigger for the LoadCommandBars procedure in Microsoft Dynamics GP, which will set the Toolbar menu item state for your toolbar. The following example is the trigger registration that creates the trigger which will update the state for the sample toolbar menu item.

l_result = Trigger_RegisterProcedure(script LoadCommandBars, TRIGGER_AFTER_ORIGINAL, script IG_SetToolbarMenuState);
if l_result <> SY_NOERR then
	warning "Procedure trigger registration failed.";
end if;

The following is the IG_SetToolbarMenuState procedure that runs in response to this trigger. It uses the CmdBarIsVisible() function to find out whether the toolbar is displayed. The checked property of the menu item is set accordingly.

local boolean visible;
local integer tag;

{Get the visible state of the sample toolbar}
visible = CmdBarIsVisible('User ID' of globals,
	IG_PROD_ID, 
	resourceid(form Command_IG_Sample),
	resourceid(command CL_IG_Sample_CMDBAR of form Command_IG_Sample)) of form syCmdBarObj;

{Set the menu item appropriately}
if visible = true then
	{Mark the menu item}
	tag = Command_GetTag(command Toolbar_IGSample of form Command_IG_Sample);
	Command_SetBooleanProperty(tag, COMMAND_PROP_CHECKED, true);
end if;


Documentation Feedback