Activating a custom toolbar

In my previous post I gave a short example of how you can use a regular form to create a new custom toolbar.

That was the easy part. You would of course want to make it easy to access the toolbar and with this post I will describe a suggestion for doing that.

Customized short cut keys is not really something you can setup in AX, so I suggest we put access to the toolbar in the menu strip under the Tools menu. We can add a menu item to start up the form to this menu very easily.

We only want one toolbar open at any time, so we’re going to have to keep track of the opened toolbar. We will use the global cache to do that.

First create a class to open the toolbar form and control that only one toolbar is open at any time:

 class aaaToolbar
{
} 

private void openToolBar()
{ 
   FormRun formRun; 
   Args args; 
   ; 
   formRun = infoLog.globalCache().get(formStr(aaaToolBar), '1', formRun); // Lookup in the global cache 

   if (!formRun) 
   { 
      args = new Args(); 
      args.name(formstr(aaaToolbar)); // Toolbar form name 
      formRun = new FormRun(args); 
      formRun.run(); 
      formRun.detach(); 

      infoLog.globalCache().set(formStr(aaaToolBar), '1', formRun); // Add to the global cache 
   } 
      else 
   { 
      formRun.setActive(); 
   }
} 

static void main(Args _args)
{ 
   aaaToolbar toolbar; ; 

   toolbar = new aaaToolbar(); toolbar.openToolBar();
} 

(Please note that AX best practice would be to create a menu item for the form too and call that rather than calling FormRun directly)

Create a menu item to start the class. The menu item must have, at least, the following properties:

Type

Display

Name

aaaToolbar

Label

Show toolbar

Class

Class

Object

aaaToolbar

Add the new menu item to the GlobalToolsMenu menu. You must restart AX in order to see it appear in the menu in the menu strip.

Finally add code to the toolbar form to remove it from the global cache when it is closed:

 public void close()
{ 
   super(); 
   infoLog.globalCache().remove(formStr(aaaToolBar), '1');
}

This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at http://www.microsoft.com/info/cpyright.htm