是否可以使用QBSDK将菜单项添加到Quickbooks?

我发现了一些我无法完成的旧示例。

我已经为我的公司创建了一个自定义应用程序,并试图通过在Quickbooks中制作一个菜单项来简化它。

任何帮助将不胜感激。

这是到目前为止我已经尝试过的方法,但是在subAdd.SubscriberID.SetValue(Me.appGUID.ToString)处收到错误消息。

错误是:*无效的GUID格式。对于自定义字段,必须使用零;对于私有数据扩展,必须使用GuidGen.exe生成的GUID。*

{
    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

最佳答案

答案是肯定的。

UIExtensionSubscription的唯一目的是将菜单项添加到顶部菜单。单击菜单将启动您的应用程序(如果尚未运行),并向其传递有关当前聚焦的Quickbooks窗口的信息。

您的应用程序必须可以通过com访问并注册。

至于您的示例,请确保在GUID周围传递{}。我不使用不确定的函数调用,您是否可能需要先强制转换为字符串。

当前从Intuit下载的QBPOSSDK中,C#中有一个示例控制台应用程序。我会仔细阅读《程序员指南》并查看该示例。

我的一项工作要求,非常接近intuit示例:

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

关于quickbooks - 将菜单项添加到Quickbooks,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16489215/

10-11 12:47