Community
Showing results for 
Search instead for 
Do you mean 
Reply

Plugin that worked with all previous versions is not working with ACT! 2011

New Member
Posts: 4
Country: USA

Plugin that worked with all previous versions is not working with ACT! 2011

When trying to add a menu item in the Application_AfterLogon function, I am attempting to access CommandBarCollection[CONNECTED_MENUBAR] which is not available (valid). This code comes directly from the CustomMenuPlugin.cs sample file. See snippet below:

 

 

        private void Application_AfterLogon(object sender, EventArgs e)
        {
            //TODO: attach to any events or perform actions

            // also, keep track of when we're about to be locked out
            application.ActFramework.Database.BeforeDatabaseLock += new Act.Framework.Database.DatabaseLockHandler(Database_BeforeDatabaseLock);


            
            // add custom menu
            AddMenuItem(CUSTOM_MENU_URN, CUSTOM_MENU_TEXT, new Act.UI.CommandHandler(DoStuff));

            this.application.ActFramework.Database.BeforeDatabaseLock += new Act.Framework.Database.DatabaseLockHandler(this.BeforeDatabaseLock);


        }

 

 

where the AddMenuItem function attempts to access the CommandBarCollection[CONNECTED_MENUBAR]. See code below:

 

 

        private void AddMenuItem(string urn, string text, Act.UI.CommandHandler Handler)
        {
            try
            {
                if (MenuItemExists(urn) == true)
                {
                    RemoveMenuItem(urn);
                }
                Act.UI.Core.CommandBarControl parentMenu = this.application.Explorer.CommandBarCollection[CONNECTED_MENUBAR].ControlCollection[GetParentControlURN(urn)];
                Act.UI.Core.CommandBarButton newMenu = new Act.UI.Core.CommandBarButton(text, text, null, urn, null, null);
                newMenu.DisplayStyle = Act.UI.Core.CommandBarControl.ItemDisplayStyle.TextOnly;
                this.application.RegisterCommand(urn, new Act.UI.CommandHandler(Handler), Act.UI.RegisterType.Shell);
                parentMenu.AddSubItem(newMenu);
            }
            catch { }
        }

 

 

Upon stepping through the debugger, the CommandBarCollection[CONNECTED_MENUBAR] is not valid (only DISCONNECTED_MENUBAR and DISCONNECTED_TOOLBAR are valid indices). The general (Windows) error box is displayed: "Object reference not set to an instance of an object". See screenshot.

Debugger snapshot

 

This code has always worked in the past versions of ACT! Any idea what is wrong? Has something changed in the ACT! code?

 

Employee
Posts: 1,163
Country: USA

Re: Plugin that worked with all previous versions is not working with ACT! 2011

[ Edited ]

Here is the working example I have that's been working for me since 2008 IIRC, hard to say what I've changed in it since then.

 

void AfterLogon(object sender, EventArgs e)
        { 
            try
            {
                AddMenuItem("act-ui://com.act/application/menu/tools/Test""Test"new Act.UI.CommandHandler(BT_Activities.GetActivityTypes));
                ActApp.ActFramework.Database.BeforeDatabaseLock += new Act.Framework.Database.DatabaseLockHandler(this.BeforeDatabaseLock);              
            }
            catch (Exception ex) { MessageBox.Show(ex.ToString()); }
        }

 

 private void AddMenuItem(string urn, string MenuTxt, Act.UI.CommandHandler handler)
        {
            try
            {
                if (MenuItemExists(urn) == true)
                {
                    RemoveMenuItem(urn);
                }
                Act.UI.Core.CommandBarControl ParentMenu = ActApp.Explorer.CommandBarCollection["Connected Menus"].ControlCollection[GetParentControlURN(urn)];
                Act.UI.Core.CommandBarButton NewMenu = new Act.UI.Core.CommandBarButton(MenuTxt, MenuTxt, null, urn, nullnull);
                NewMenu.DisplayStyle = Act.UI.Core.CommandBarControl.ItemDisplayStyle.TextOnly;
                ActApp.RegisterCommand(urn, new Act.UI.CommandHandler(handler), Act.UI.RegisterType.Shell);
                ParentMenu.AddSubItem(NewMenu);
            }
            catch (Exception ex) { MessageBox.Show(ex.ToString()); }
        }

 

 

 

void AfterLogon(object sender, EventArgs e)
        { 
            try
            {
                AddMenuItem("act-ui://com.act/application/menu/tools/Test""Test"new Act.UI.CommandHandler(BT_Activities.GetActivityTypes));
                ActApp.ActFramework.Database.BeforeDatabaseLock += new Act.Framework.Database.DatabaseLockHandler(this.BeforeDatabaseLock);
                ActApp.ActFramework.Activities.ActivityCleared += new ActivityManager.ClearActivityDelegate(Activities_ActivityCleared);
                ActApp.CurrentContactChanged += new EventHandler(ActApp_CurrentContactChanged);
                ActApp.ViewLoaded += new ViewEventHandler(ActApp_ViewLoaded);
            }
            catch (Exception ex) { MessageBox.Show(ex.ToString()); }
        }
Matthew Wood
Act! SDK Support
Community Moderator