QuickBooks POS SDK添加客户自定义字段数据:DataExtAdd

时间:2014-07-29 20:15:01

标签: c# quickbooks qbfc

任何人都可以帮助将数据添加到QuickBooks POS 2013中定义的自定义字段吗?

我正在尝试将数据添加到UI定义的自定义字段(在POS用户界面中创建并显示该字段,而不是通过编程;因此OnwerID为“0”)从网页添加新客户时。

我正在使用:在Microsoft Visual Studio 2012 WebForms,C#.NET,QBPOSFC3Lib中创建应用程序,与QB POS 2013 Pro交谈。应用程序和QBPOS服务器都在/打开并在同一台服务器上运行。

目标:客户在网页上输入信息。数据包括QBPOS作为其核心编程的一部分跟踪的11个属性,以及需要记录并在UI的自定义字段中定义的7个属性。在客户输入信息并使用方法(不包括在下面的代码中)验证数据以进行格式化和要求之后,下面的代码运行以将数据发送到QBPOS服务器。 注意:AddCustomer命令可以100%运行。

程序流程:在下面的代码中,我正在制作客户添加请求(CstReq)并仅为ListID获取客户添加响应(CstResp)。使用一种方法7次创建7个请求,将数据添加到自定义字段(我将6个中的6个注释为“可能就是问题”并仅使用一个DataExtAddRq进行测试)和CstResp ListID(我不问(在程序中)或需要DataExtAddRq的响应)。然后是EndSession和CloseConnection(调试我在CstReq之后结束并关闭并在DataExtAdd之前重新打开,结果没有变化)。

问题:DataExtAddRq未将信息添加到自定义字段。在制作客户并且程序访问DataExtAdd部件后,它会将相同的客户数据添加到QBPOS,并且不会添加Ext数据(var requestMsgSet在DataExtAdd之前变为null)。

有问题的代码:

protected void DoCustomerAdd()
    {

        bool sessionBegun = false;
        bool connectionOpen = false;
        QBPOSSessionManager sessionManager = null;

        try
        {
            String custDateOfBirth = KEY_BIRTHDATE.Text;
            String custExpLevel = KEY_EXPERIENCE.Text;
            String custCNum = KEY_C_NUM.Text;
            String custCExpDate = KEY_C_EXP.Text;
            String custMemCardNun = textMembershipNumber.Text;
            String custIDNum = KEY_ID_NUM.Text;
            String custWaiverAppr = "Yes";

                //Create the session Manager object
            sessionManager = new QBPOSSessionManager();

                //Create the message set request object to hold our request
            IMsgSetRequest requestMsgSet = sessionManager.CreateMsgSetRequest(3, 0);
            requestMsgSet.Attributes.OnError = ENRqOnError.roeContinue;

            BuildCustomerAddRq(requestMsgSet);//Call

                //Connect to QuickBooks and begin a session
            sessionManager.OpenConnection("AddCust", "MyApp");
            connectionOpen = true;
            sessionManager.BeginSession("");
            sessionBegun = true;

                //Send the request to QuickBooks and get response
            IMsgSetResponse responseMsgSet = sessionManager.DoRequests(requestMsgSet);

                //look at response and get customer list id, needed for adding custom fields
            IResponse response = responseMsgSet.ResponseList.GetAt(0);
            ICustomerRet CustomerRet = (ICustomerRet)response.Detail;
            string custListID = CustomerRet.ListID.GetValue();

                //End the session and close the connection to QuickBooks
            sessionManager.EndSession();
            sessionBegun = false;
            sessionManager.CloseConnection();
            connectionOpen = false;

            requestMsgSet = null;

//////////////////////////////////////////////////////////////////////////////


            //Create the session Manager object
            sessionManager = new QBPOSSessionManager();

            //Create the message set request object to hold our request
            requestMsgSet = sessionManager.CreateMsgSetRequest(3, 0);
            requestMsgSet.Attributes.OnError = ENRqOnError.roeContinue;

            AddCustomerCustField(requestMsgSet, custListID, "C Number", custCNum);

            //Connect to QuickBooks and begin a session
            sessionManager.OpenConnection("AddCust", "MyApp");
            connectionOpen = true;
            sessionManager.BeginSession("");
            sessionBegun = true;

            //add to customfields

            sessionManager.DoRequests(requestMsgSet);

                /*/
            AddCustomerCustField(requestMsgSet, custListID, "Experience Level", custExpLevel);
            AddCustomerCustField(requestMsgSet, custListID, "Date of Birth", custDateOfBirth);
            sessionManager.DoRequests(requestMsgSet);
            AddCustomerCustField(requestMsgSet, custListID, "C Number", custCNum);
            sessionManager.DoRequests(requestMsgSet);
            AddCustomerCustField(requestMsgSet, custListID, "C Experation Date", custCExpDate);
            sessionManager.DoRequests(requestMsgSet);
            AddCustomerCustField(requestMsgSet, custListID, "Member Number", custMemCardNun);
            sessionManager.DoRequests(requestMsgSet);
            AddCustomerCustField(requestMsgSet, custListID, "Waiver Approved", custWaiverAppr);
            sessionManager.DoRequests(requestMsgSet);
            AddCustomerCustField(requestMsgSet, custListID, "ID Number", custDrivLiceNum);
            sessionManager.DoRequests(requestMsgSet);
            /*/

            sessionManager.EndSession();
            sessionBegun = false;
            sessionManager.CloseConnection();
            connectionOpen = false;

        }
        catch (Exception q)
        {
            if (sessionBegun) { } //sessionManager.EndSession();
            if (connectionOpen) { } //sessionManager.CloseConnection();
        }

    } //End DoCustomerAdd

    void BuildCustomerAddRq(IMsgSetRequest requestMsgSet)
    {
        String CustFirstName = KEY_FIRST_NAME.Text;
        String CustLastName = KEY_LAST_NAME.Text;
        //String CustCompanyName = TextBox.Text;
        String CustEMail = KEY_EMAIL.Text;
        bool CustIsOkToEMail = emailList.Checked;
        String CustPhone2 = KEY_PHONE.Text;
        String CustStreet = KEY_ADDRESS.Text;
        String CustCity = KEY_CITY.Text;
        String CustState = KEY_STATE.Text;
        String CustPostalCode = KEY_ZIP.Text;
        String CustCountry = "US";
        String CustType = textResultMembershipLevel.Text;

        ICustomerAdd CustomerAddRq = requestMsgSet.AppendCustomerAddRq();

            //Set field value's
        //CustomerAddRq.CompanyName.SetValue(CustCompanyName);
        CustomerAddRq.EMail.SetValue(CustEMail);
        CustomerAddRq.IsOkToEMail.SetValue(CustIsOkToEMail);
        CustomerAddRq.FirstName.SetValue(CustFirstName);
        CustomerAddRq.LastName.SetValue(CustLastName);
        CustomerAddRq.Phone2.SetValue(CustPhone2); //Cell
        CustomerAddRq.BillAddress.City.SetValue(CustCity);
        CustomerAddRq.BillAddress.Country.SetValue(CustCountry);
        CustomerAddRq.BillAddress.PostalCode.SetValue(CustPostalCode);
        CustomerAddRq.BillAddress.State.SetValue(CustState);
        CustomerAddRq.BillAddress.Street.SetValue(CustStreet);
        CustomerAddRq.CustomerType.SetValue(CustType);

    } //End BuildCustomerAddRq

    public void AddCustomerCustField(IMsgSetRequest requestMsgSet, String custListID, String fieldName, String enterData)
    {
        IDataExtAdd DataExtAddRq = requestMsgSet.AppendDataExtAddRq();
        DataExtAddRq.OwnerID.SetValue("0"); //field visable in UI so it is "0"
        DataExtAddRq.DataExtName.SetValue(fieldName); //name of field
        string ORDataExtOwnerElementType = "ListDataExt";
        if (ORDataExtOwnerElementType == "ListDataExt")
        {
            //set for customer add
            DataExtAddRq.ORDataExtOwner.ListDataExt.ListDataExtType.SetValue(ENListDataExtType.ldetCustomer);
            //give list id for cust
            DataExtAddRq.ORDataExtOwner.ListDataExt.ListObjRef.ListID.SetValue(custListID);
        }
        if (ORDataExtOwnerElementType == "OtherDataExtType")
        {
            //Set field value for OtherDataExtType
            DataExtAddRq.ORDataExtOwner.OtherDataExtType.SetValue(ENOtherDataExtType.odetCompany);
        }
            //Set field value for DataExtValue
        DataExtAddRq.DataExtValue.SetValue(enterData);


    } //End AddCustomerCustField

感谢您的帮助,但请在帮助之前阅读分析。

1 个答案:

答案 0 :(得分:0)

我做了一些测试,发现了可能导致问题的bug。我使用了默认的自定义字段名称"自定义1"并收到错误响应"扩展错误(数据扩展名包含无效字符:"自定义1")"。我知道这是自定义字段的名称,它是活动的。我将字段的名称更改为" Custom1" (没有空格)并且能够更新该字段。

查看代码,所有字段似乎都有空格。我相信POS SDK中存在一个错误,它不允许自定义字段名称中的空格。如果您尝试将字段更改为不包含空格,那么您仍然遇到问题吗?

另外,请记住,如果在进行更改时客户屏幕处于打开状态,您有时需要关闭并返回客户屏幕以查看更新。它不会像在QuickBooks中那样触发屏幕刷新。