Question

can anyone help with adding data to a UI defined Custom Field in QuickBooks POS 2013?

I am trying to add data to a UI defined custom field (the field was made and visible in the POS user interface, not by programing; so the OnwerID is “0”) when adding a new customer from a web page.

I am using: creating the application in Microsoft Visual Studio 2012 WebForms, C# .NET, QBPOSFC3Lib, talking to QB POS 2013 Pro. The application and QBPOS-server are both on/open and running on the same server.

Goal: a customer enters information on to the web page. Data includes 11 attributes that QBPOS tracks as part of its core programing, and 7 attributes that need to be recorded and are defined in the UI’s Custom Fields. After the customer enters the information and the data is verified with methods (not include in the below code) for formatting and requirements then the below code runs to send the data to the QBPOS-server. Note: The AddCustomer command works 100%.

Program Process: In the below code I am making the Customer Add Request (CstReq) and getting the Customer Add Response (CstResp) for only the ListID. Using one method 7 times to create 7 requests to add data to the custom fields (I commented out 6 of the 7 as a “perhaps that is the problem” and testing with only one DataExtAddRq) with the CstResp ListID (I do not ask (in the program) or need a Response for the DataExtAddRq). Then EndSession and CloseConnection (to debug I end and close after the CstReq and reopen before DataExtAdd, no change in result).

Problem: the DataExtAddRq is not adding the information to the custom fields. After the customer is made and the program hits the DataExtAdd part, it adds the same customer data to QBPOS and doesn’t add the Ext data (var requestMsgSet is made null before DataExtAdd).

Code in question:

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

Thank you for any help, but please read the analysis before helping.

Was it helpful?

Solution

I did some testing and found what might be a bug that is causing your problem. I used the default custom field name, "Custom 1" and got an error response "Extension error (The data extension name contains invalid character(s): "Custom 1")". I know this is the name of the custom field, and it is active. I changed the name of the field to "Custom1" (with no space) and was able to update the field.

Looking at your code, all the fields seem to have spaces in them. I believe there is a bug in the POS SDK that doesn't allow for spaces in the custom field names. If you try changing the fields to not include spaces, do you still have the problem?

Also, keep in mind that if the customer screen is open when you make the change, you sometimes need to close out and go back to the customer screen to see the updates. It doesn't trigger a screen refresh like it does in QuickBooks.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top