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

本文关键字:字段 数据 DataExtAdd 自定义 客户 POS SDK 添加 QuickBooks | 更新日期: 2023-09-27 18:15:44

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

我试图将数据添加到UI定义的自定义字段(该字段在POS用户界面中制作和可见,而不是通过编程;所以OnwerID是" 0 "),当从一个网页添加一个新客户。

我正在使用:在Microsoft Visual Studio 2012 WebForms, c# . net, QBPOSFC3Lib中创建应用程序,与QBPOS 2013 Pro交谈。应用程序和QBPOS-server都在/open上,并且运行在同一台服务器上。

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

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

问题:DataExtAddRq没有将信息添加到自定义字段。客户创建后,程序点击DataExtAdd部分,它将相同的客户数据添加到QBPOS中,而不添加Ext数据(var requestMsgSet在DataExtAdd之前为空)。

问题代码:

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

谢谢你的帮助,但是在帮助之前请先阅读分析

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

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

看看你的代码,所有的字段似乎都有空格。我相信POS SDK中有一个错误,不允许在自定义字段名称中使用空格。如果您尝试更改字段以不包含空格,您还会遇到问题吗?

另外,请记住,如果在进行更改时客户屏幕是打开的,则有时需要关闭客户屏幕并返回到客户屏幕以查看更新。它不像QuickBooks那样触发屏幕刷新