Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Import & Export Custom Fields For Customer List in QuickBooks

In Quickbooks Pro 2009 I'm Adding and Importing list of Customers through the C# windows application. In quick book itself Import and Export options are there for customers list, but we have defined our own business validations logics and we are pushing the data to Quick book DB for customers.

In Quick Book there is a option to define custom fields under Additional Tab.

While programmatically adding Quick Book List of Customers, I'm able to add the values for Built-In Field values Like Customer Name Company Name and Etc. If I try to push the data for custom fields. Its giving me the error...

QuickBooks found an error when parsing the provided XML text stream.

If I skip the custom field data pushing operation then defined fields data passing is working fine.

My Code:

    XmlDocument inputXMLDoc = new XmlDocument();
    inputXMLDoc.AppendChild(inputXMLDoc.CreateXmlDeclaration("1.0", null, null));
    inputXMLDoc.AppendChild(inputXMLDoc.CreateProcessingInstruction("qbxml", "version=\"2.0\""));
    XmlElement qbXML = inputXMLDoc.CreateElement("QBXML");
    inputXMLDoc.AppendChild(qbXML);
    XmlElement qbXMLMsgsRq = inputXMLDoc.CreateElement("QBXMLMsgsRq");
    qbXML.AppendChild(qbXMLMsgsRq);
    qbXMLMsgsRq.SetAttribute("onError", "stopOnError");
    XmlElement custAddRq = inputXMLDoc.CreateElement("CustomerAddRq");
    qbXMLMsgsRq.AppendChild(custAddRq);
    custAddRq.SetAttribute("requestID", "1");
    XmlElement custAdd = inputXMLDoc.CreateElement("CustomerAdd");
    custAddRq.AppendChild(custAdd);

    //In-Built Columns
    custAdd.AppendChild(inputXMLDoc.CreateElement("Name")).InnerText = Name;
    custAdd.AppendChild(inputXMLDoc.CreateElement("AccountNumber")).InnerText = AccountNumber;

    //Defined Custom Columns
    custAdd.AppendChild(inputXMLDoc.CreateElement("CUSTFLD1")).InnerText = JRNL_NO;

    String name = CustName.Text.Trim();

    string input = inputXMLDoc.OuterXml;

    //Push the Data to do the qbXMLRP request
    RequestProcessor2 rp = null;
    string ticket = null;
    string response = null;
    try
    {
        rp = new RequestProcessor2();
        rp.OpenConnection("", "IDN CustomerAdd C# sample");
        ticket = rp.BeginSession("", QBFileMode.qbFileOpenDoNotCare);
        response = rp.ProcessRequest(ticket, input);

    }
    catch (System.Runtime.InteropServices.COMException ex)
    {
        MessageBox.Show("COM Error Description = " + ex.Message, "COM error");
    }

What am I doing wrong here.. any helps?? or any suggestions / Ideas ????

like image 900
RajeshKdev Avatar asked Aug 13 '13 06:08

RajeshKdev


People also ask

How does an import work?

An import is a good or service bought in one country that was produced in another. Imports and exports are the components of international trade. If the value of a country's imports exceeds the value of its exports, the country has a negative balance of trade, also known as a trade deficit.


1 Answers

QuickBooks has a very specific syntax you have to follow (defined by an XML .XSD) when creating requests for it to process. You can't just make up new XML nodes and expect them to work.

Thus, this is going to break things:

//Defined Custom Columns
custAdd.AppendChild(inputXMLDoc.CreateElement("CUSTFLD1")).InnerText = JRNL_NO;

Custom fields are added/modified by sending DataExt requests to QuickBooks. They are entirely separate from the main CustomerAdd or CustomerMod request. To add the custom fields, you can either send an entirely separate request:

<?xml version="1.0" encoding="utf-8"?>
<?qbxml version="7.0"?>
<QBXML>
    <QBXMLMsgsRq onError="stopOnError">
        <DataExtModRq>
            <DataExtMod>
                <OwnerID>0</OwnerID>
                <DataExtName>Your Custom Field Name</DataExtName>
                <ListDataExtType>Customer</ListDataExtType>
                <ListObjRef>
                    <FullName>Your Customer Name</FullName>
                </ListObjRef>
                <DataExtValue>Custom field value</DataExtValue>
            </DataExtMod>
        </DataExtModRq>
    </QBXMLMsgsRq>
</QBXML>

Or, you can chain the two requests together:

<?xml version="1.0" encoding="utf-8"?>
<?qbxml version="7.0"?>
<QBXML>
    <QBXMLMsgsRq onError="stopOnError">

        <CustomerAddRq requestID="Q3VzdG9tZXJBZGR8MTExMTIxMjE=">
            <CustomerAdd>
                <Name>Keith Palmer Jr.</Name>
                <FirstName>Keith</FirstName>
                <MiddleName></MiddleName>
                <LastName>Palmer Jr.</LastName>
                <BillAddress>
                    <Addr1>134 Stonemill Road</Addr1>
                    <City>Mansfield</City>
                    <State>CT</State>
                    <PostalCode>06268</PostalCode>
                    <Country>USA</Country>
                </BillAddress>
                <Phone>999-99-9999</Phone>
                <Email>[email protected]</Email>
                <Contact>Keith Palmer Jr.</Contact>
            </CustomerAdd>
        </CustomerAddRq>

        <DataExtModRq>
            <DataExtMod>
                <OwnerID>0</OwnerID>
                <DataExtName>Your Custom Field Name</DataExtName>
                <ListDataExtType>Customer</ListDataExtType>
                <ListObjRef>
                        <FullName>Keith Palmer Jr.</FullName>
                </ListObjRef>
                <DataExtValue>Custom field value</DataExtValue>
            </DataExtMod>
        </DataExtModRq>

    </QBXMLMsgsRq>
</QBXML>

Additional examples can be found on our QuickBooks development wiki.

like image 102
Keith Palmer Jr. Avatar answered Sep 20 '22 04:09

Keith Palmer Jr.