0

Before, I had this program working. However, im not sure if I either deleted something, or i forgot to add something, but the more I look at it, the less wrong it looks.

Maybe all I need is a fresh pair of eyes to look at it, but from what I can tell, this is 100% correct, and the breakpoints tell me that everything is correct.

This isn't adding to quickbooks inventory, I don't know why, it doesn't make sense.

        public void ProductAdd(IMsgSetRequest requestMsgSet)
    {
        IItemInventoryAdd itemInventoryAddRq = requestMsgSet.AppendItemInventoryAddRq();

        #region ADD PRODUCT INFORMATION
        for (int i = 0; i <= this.Form.productsList.Items.Count - 1; i++)
        {

            itemInventoryAddRq.Name.SetValue(Form.productID[i].ToString());
            itemInventoryAddRq.SalesDesc.SetValue(Form.productsList.Items[i].ToString().ToUpper());
            itemInventoryAddRq.PurchaseDesc.SetValue(Form.productsList.Items[i].ToString().ToUpper());
            itemInventoryAddRq.SalesPrice.SetValue(Form.QBprice[i]);
            itemInventoryAddRq.AssetAccountRef.FullName.SetValue("Inventory Asset");
            itemInventoryAddRq.COGSAccountRef.FullName.SetValue("Cost of Goods Sold");
            itemInventoryAddRq.ManufacturerPartNumber.SetValue(Form.QBsku[i].ToString().ToUpper());

            IMsgSetResponse responseMsgSet = sessionManager.DoRequests(requestMsgSet);
        }

        #endregion
    }
Alex Moreno
  • 138
  • 1
  • 13
  • On first inspection, I notice in your for loop you use i <= this.Form.productsList.Items.Count - 1, and wonder why you don't just do this instead: i < this.Form.productsList.Items.Count – Pharap Jul 09 '13 at 20:46
  • the loop starts at 0, not 1. if i remove the -1, its going to go through the loop an extra time, and find out that theirs insufficient items. the loop works as is. its just quickbooks isn't adding the item, either missing information, or something of the sort. – Alex Moreno Jul 09 '13 at 20:51
  • I know it starts at 0, look again. I'm saying remove the -1 and swap the <= for a <. They resolve to the same thing, but the second method uses less code and it's clearer what's going on. – Pharap Jul 09 '13 at 20:57
  • Alright, but i still have the same problem. – Alex Moreno Jul 09 '13 at 21:05
  • Did you check the error code/message that you got back from QuickBooks? What does it say? – Keith Palmer Jr. Jul 10 '13 at 02:50
  • Hey, I got it to work, i just sent everything to a new project and it worked. rather weird. thanks though. – Alex Moreno Jul 10 '13 at 18:34

1 Answers1

0

I tend to get odd behavior when I have my Append request outside of the loop. Even though it should be creating an item each time, the SessionManager.DoRequests doesn't always seem to work like you have it. I would rewrite the loop like this:

public void ProductAdd(IMsgSetRequest requestMsgSet)
{
    #region ADD PRODUCT INFORMATION
    for (int i = 0; i <= this.Form.productsList.Items.Count - 1; i++)
    {

        IItemInventoryAdd itemInventoryAddRq = requestMsgSet.AppendItemInventoryAddRq();

        itemInventoryAddRq.Name.SetValue(Form.productID[i].ToString());
        itemInventoryAddRq.SalesDesc.SetValue(Form.productsList.Items[i].ToString().ToUpper());
        itemInventoryAddRq.PurchaseDesc.SetValue(Form.productsList.Items[i].ToString().ToUpper());
        itemInventoryAddRq.SalesPrice.SetValue(Form.QBprice[i]);
        itemInventoryAddRq.AssetAccountRef.FullName.SetValue("Inventory Asset");
        itemInventoryAddRq.COGSAccountRef.FullName.SetValue("Cost of Goods Sold");
        itemInventoryAddRq.ManufacturerPartNumber.SetValue(Form.QBsku[i].ToString().ToUpper());

    }

    IMsgSetResponse responseMsgSet = sessionManager.DoRequests(requestMsgSet);
    #endregion
}
Hpjchobbes
  • 1,309
  • 1
  • 8
  • 11