0

QBWC(QBXML) : How to update Inventory/Non Inventory Item in QuickBooks if it's already exist.

I am using WCF service.Here is sendrequestxml and receiveResponseXML function.

public string sendRequestXML(string ticket, string strHCPResponse, string strCompanyFileName,
        string qbXMLCountry, int qbXMLMajorVers, int qbXMLMinorVers)
    {

        if (System.Web.HttpContext.Current.Session["counter"] == null)
        {
            System.Web.HttpContext.Current.Session["counter"] = 0;
        }
        string evLogTxt = "WebMethod: sendRequestXML() has been called by QBWebconnector" + "\r\n\r\n";
        evLogTxt = evLogTxt + "Parameters received:\r\n";
        evLogTxt = evLogTxt + "string ticket = " + ticket + "\r\n";
        evLogTxt = evLogTxt + "string strHCPResponse = " + strHCPResponse + "\r\n";
        evLogTxt = evLogTxt + "string strCompanyFileName = " + strCompanyFileName + "\r\n";
        evLogTxt = evLogTxt + "string qbXMLCountry = " + qbXMLCountry + "\r\n";
        evLogTxt = evLogTxt + "int qbXMLMajorVers = " + qbXMLMajorVers.ToString() + "\r\n";
        evLogTxt = evLogTxt + "int qbXMLMinorVers = " + qbXMLMinorVers.ToString() + "\r\n";
        evLogTxt = evLogTxt + "\r\n";

        req = (ArrayList)System.Web.HttpContext.Current.Session["RequestList"];

        if (req == null)
        {
            req = buildRequest(ticket);
            System.Web.HttpContext.Current.Session["RequestList"] = req;
        }
        string request = "";
        int total = req.Count;
        count = Convert.ToInt32(System.Web.HttpContext.Current.Session["counter"]);

        if (count < total)
        {
            request = req[count].ToString();
            evLogTxt = evLogTxt + "sending request no = " + (count + 1) + "\r\n";
            System.Web.HttpContext.Current.Session["counter"] = ((int)System.Web.HttpContext.Current.Session["counter"]) + 1;
        }
        else
        {
            count = 0;
            System.Web.HttpContext.Current.Session["counter"] = 0;
            request = "";
        }
        evLogTxt = evLogTxt + "\r\n";
        evLogTxt = evLogTxt + "Return values: " + "\r\n";
        evLogTxt = evLogTxt + "string request = " + request + "\r\n";
        logEvent(evLogTxt);
        return request;
    }

 public int receiveResponseXML(string ticket, string response, string hresult, string message)
    {
        string evLogTxt = "WebMethod: receiveResponseXML() has been called by QBWebconnector" + "\r\n\r\n";
        evLogTxt = evLogTxt + "Parameters received:\r\n";
        evLogTxt = evLogTxt + "string ticket = " + ticket + "\r\n";
        evLogTxt = evLogTxt + "string response = " + response + "\r\n";
        evLogTxt = evLogTxt + "string hresult = " + hresult + "\r\n";
        evLogTxt = evLogTxt + "string message = " + message + "\r\n";
        evLogTxt = evLogTxt + "\r\n";

        int retVal = 0;
        if (!hresult.ToString().Equals(""))
        {
            // if there is an error with response received, web service could also return a -ve int     
            evLogTxt = evLogTxt + "HRESULT = " + hresult + "\r\n";
            evLogTxt = evLogTxt + "Message = " + message + "\r\n";
            retVal = -101;
        }
        else
        {
            evLogTxt = evLogTxt + "Length of response received = " + response.Length + "\r\n";
            req = (ArrayList)System.Web.HttpContext.Current.Session["RequestList"];
            if (req == null)
            {
                req = buildRequest(ticket);
            }
            int total = req.Count;
            int count = Convert.ToInt32(System.Web.HttpContext.Current.Session["counter"]);

            int percentage = (count * 100) / total;
            if (count == 60)
            {
                if (percentage >= 100)
                {
                    count = 0;
                    System.Web.HttpContext.Current.Session["counter"] = 0;
                }
            }
            retVal = percentage;
        }
        evLogTxt = evLogTxt + "\r\n";
        evLogTxt = evLogTxt + "Return values: " + "\r\n";
        evLogTxt = evLogTxt + "int retVal= " + retVal.ToString() + "\r\n";
        logEvent(evLogTxt);
        return retVal;
    }

I am familiar with QB error code. If item already exist then it gives you error like Item already exist, but how to handle that error and generate another new request to for update that item.

Can anyone guide me how to update item in QuickBooks?

gleng
  • 6,185
  • 4
  • 21
  • 35
  • 1
    Instead of doing an add, you will need to do a query and then a mod using the data from the query to update the information you need to. – William Lorfing Oct 29 '13 at 13:43
  • If item not exist in QuickBooks then update will add new item in QuickBooks? Do you have sample code for item query and update item. – Kajal Kathiriya Oct 29 '13 at 15:13
  • To expand on William's comment, you need to do an `ItemQueryRq` request with proper filters to retrieve the `EditSequence` for the item. If the item does not exist, you can create a new item, otherwise you need to do a `ItemInventoryModRq` or `ItemNonInventoryModRq` to modify the item. – Jeremy Dec 03 '13 at 17:36

0 Answers0