3

Is it possible to add a menu item to Quickbooks using the QBSDK?

I have found a couple of old examples that I can't make work.

I have created a custom application for my company and am trying to simplify it by making a menu item in Quickbooks.

Any help would be greatly appreciated.

Here is what I have tried so far, but I get an error message at the subAdd.SubscriberID.SetValue(Me.appGUID.ToString).

The error is: * Invalid GUID format. Must use zero for Custom Fields, or a GUID generated with GuidGen.exe for private data extensions.*

{
    Dim subRq As ISubscriptionMsgSetRequest
    subRq = MySessionManager.CreateSubscriptionMsgSetRequest(4, 0)
    ' Add a UIExtension subscription to our request
    Dim subAdd As IUIExtensionSubscriptionAdd
    subAdd = subRq.AppendUIExtensionSubscriptionAddRq

    '
    ' set up the subscription request with the required information, we're adding to
    ' the file menu in this case, and just for fun, we're making it a cascading menu
    subAdd.SubscriberID.SetValue(Me.appGUID.ToString) "<-----error happens here
    subAdd.COMCallbackInfo.AppName.SetValue(Me.appName)

    subAdd.COMCallbackInfo.ORProgCLSID.ProgID.SetValue("MenuEventContext.QBMenuListener")
    subAdd.MenuExtensionSubscription.AddToMenu.SetValue("atmFile")

    '
    ' For the cascade fun, we're just going to add items to the cascade menu...
    Dim subMenu As IMenuItem
    For i = 1 To 5
        subMenu = subAdd.MenuExtensionSubscription.ORMenuSubmenu.Submenu.MenuItemList.Append
        '
        ' this is the text that the user will see in QuickBooks:
        subMenu.MenuText.SetValue("Sub Item " & i)
        '
        ' this is the tag we'll get in our event handler to know which menu item was
        ' selected:
        subMenu.EventTag.SetValue("SubMenu" & i)
    Next i

    '
    ' Send the request and get the response, since we're sending only one request there
    ' will be only one response in the response list
    Dim subRs As ISubscriptionMsgSetResponse
    subRs = MySessionManager.DoSubscriptionRequests(subRq)
    Dim resp As IResponse

    '
    ' Check the response and display an appropriate message to the user.
    resp = subRs.ResponseList.GetAt(0)
    If (resp.StatusCode = 0) Then
        MsgBox("Successfully added to QuickBooks File menu, restart QuickBooks to see results")
    Else
        MsgBox("Could not add to QuickBooks menu: " & resp.StatusMessage)
    End If
    MySessionManager.CloseConnection()
    MySessionManager = Nothing
    Exit Sub
   handleError:
    MsgBox("Encountered error subscribing: " & Err.Description)
    If Not MySessionManager Is Nothing Then
        MySessionManager.CloseConnection()
    End If


End Sub
Keith Palmer Jr.
  • 27,666
  • 16
  • 68
  • 105
Clint Clark
  • 173
  • 3
  • 14

1 Answers1

3

The answer is yes.

The only purpose of UIExtensionSubscription is to add menu items to the top menus. Clicking the menus will then start your app, if it isn't already running, and pass it information about the current focused Quickbooks window.

Your application must be com accessible and registered.

As for your sample make sure you are passing { } around your GUID. I don't use function call unsure if you might need to cast to a string first or not.

There is a sample console app in C# in the current QBPOSSDK download from Intuit. I would thoroughly read the programmers guide and look at that sample.

One of my working requests, pretty close to the intuit sample:

Private Shared Function GetUIExtensionSubscriptionAddXML(ByVal strMenuName As String, ByVal strMainMenuName As String) As String
        'strMainMenuName would be "Company" for example
        'Create the qbXML request
        Dim requestXMLDoc As New XmlDocument()
        requestXMLDoc.AppendChild(requestXMLDoc.CreateXmlDeclaration("1.0", Nothing, Nothing))
        requestXMLDoc.AppendChild(requestXMLDoc.CreateProcessingInstruction("qbxml", "version=""5.0"""))
        Dim qbXML As XmlElement = requestXMLDoc.CreateElement("QBXML")
        requestXMLDoc.AppendChild(qbXML)

        'subscription Message request
        Dim qbXMLMsgsRq As XmlElement = requestXMLDoc.CreateElement("QBXMLSubscriptionMsgsRq")
        qbXML.AppendChild(qbXMLMsgsRq)

        'UI Extension Subscription ADD request
        Dim uiExtSubscriptionAddRq As XmlElement = requestXMLDoc.CreateElement("UIExtensionSubscriptionAddRq")
        qbXMLMsgsRq.AppendChild(uiExtSubscriptionAddRq)


        'UI Extension Subscription ADD
        Dim uiExtEventSubscriptionAdd As XmlElement = requestXMLDoc.CreateElement("UIExtensionSubscriptionAdd")
        uiExtSubscriptionAddRq.AppendChild(uiExtEventSubscriptionAdd)

        'Add Subscription ID
        uiExtEventSubscriptionAdd.AppendChild(requestXMLDoc.CreateElement("SubscriberID")).InnerText = MySubscriberGUID

        'Add COM CallbackInfo
        Dim comCallbackInfo As XmlElement = requestXMLDoc.CreateElement("COMCallbackInfo")
        uiExtEventSubscriptionAdd.AppendChild(comCallbackInfo)

        'Appname and CLSID
        comCallbackInfo.AppendChild(requestXMLDoc.CreateElement("AppName")).InnerText = App_Name
        comCallbackInfo.AppendChild(requestXMLDoc.CreateElement("CLSID")).InnerText = MyCLSID


        '  MenuEventSubscription
        Dim menuExtensionSubscription As XmlElement = requestXMLDoc.CreateElement("MenuExtensionSubscription")
        uiExtEventSubscriptionAdd.AppendChild(menuExtensionSubscription)

        'Add To menu
        menuExtensionSubscription.AppendChild(requestXMLDoc.CreateElement("AddToMenu")).InnerText = strMainMenuName

        Dim menuItem As XmlElement = requestXMLDoc.CreateElement("MenuItem")
        menuExtensionSubscription.AppendChild(menuItem)

        'Add Menu Name
        menuItem.AppendChild(requestXMLDoc.CreateElement("MenuText")).InnerText = strMenuName
        menuItem.AppendChild(requestXMLDoc.CreateElement("EventTag")).InnerText = "menu_" & strMenuName.Replace(" ", "_")


        Dim displayCondition As XmlElement = requestXMLDoc.CreateElement("DisplayCondition")
        menuItem.AppendChild(displayCondition)

        displayCondition.AppendChild(requestXMLDoc.CreateElement("VisibleIf")).InnerText = "InventoryEnabled"
        displayCondition.AppendChild(requestXMLDoc.CreateElement("EnabledIf")).InnerText = "InventoryEnabled"

        Dim strRetString As String = requestXMLDoc.OuterXml
        WriteLocalLog("GetUIExtensionSubscriptionAddXML: " & strRetString)
        Return strRetString   
End Function
Comivan
  • 100
  • 7
  • Hello Comivan , I have a problem to Subscribe the menu under file i fallow your code it's working but it won't show my menu name under file but if i check Edit--> preferences-->Integrted Applications-->company preferences there it shows my appname . did i mistake any thing or is there any modification .. please help me .I'm using QB2013 version... – Victor Athoti. May 03 '14 at 12:15
  • Something the documentation doesn't cover (cause it is older than UAC) Is after your Request to modify the menu is you have to run QuickBooks as administrator. Once it is modified you don't need to run it elevated anymore. – Comivan May 05 '14 at 20:27
  • @Comivan I'm trying to figure out the whole menu item thing, I was wondering if you could point me to some sample code for how the COM stuff needs to be configured/handled on the receivers end, (I have an existing winforms application that I want to make launch-able through a QB Menu option, I don't need any data passed back & forth at any point). Another question I have regarding COM, does my application need to be running as a service in order for it to receive the event from QB? or will QB launch it? Any help is appreciated, Thanks. – effy Feb 27 '19 at 17:34