Quickbooks SDK: Step by Step guide to read Custom Fields using QBFC in C#

Quickbooks SDK: Step by Step guide to read Custom Fields using QBFC in C#

Published Date: 2/23/2018

1. First of all we need to add a reference to Interop.QBFC13.dll and add the Interop.QBFC13 namespace to the top of the page.

using Interop.QBFC13;


2. To request data from QuickBooks we create a QBSessionManager and open a connection. For this request to work, we need to have QuickBooks open and logged in to a company file.

QBSessionManager _MySessionManager = new QBSessionManager();
    _MySessionManager.OpenConnection2("", "Your App Name", ENConnectionType.ctLocalQBD);
    _MySessionManager.BeginSession("", ENOpenMode.omDontCare);


3. We create a IMsgSetRequest. We will need to append our request to this message set.

IMsgSetRequest itemRequestset = _MySessionManager.CreateMsgSetRequest("US", 13, 0);


4. We then append our request to the above Message Set, in this example we want to get a list of all items from QuickBooks, so we add a AppendItemQueryRq().

IItemQuery itemQuery = itemRequestset.AppendItemQueryRq();


5. We add 0 as OwnerID to give us all the items. Read more about OwnerID in the QBSDK Programmer’s Guide.



6. We then send the request to QuickBooks and we get our response in the form of a list. In this example we have performed only one request AppendItemQueryRq so the first item “position 0” in the itemResponseList is the object we need.

IMsgSetResponse responseItemRq = _MySessionManager.DoRequests(itemRequestset); IResponseList itemResponseList = responseItemRq.ResponseList; IResponse itemResponse = itemResponseList.GetAt(0);


7. Here we have performed only one request and we know that the response will always be a list of Items, so we convert the itemResponse.detail to a IORItemRetList

IORItemRetList QBItemList = (IORItemRetList)itemResponse.Detail;


8. Now we iterate our item list.

for (int i = 0; i <= QBItemList.Count - 1; i++)
    IDataExtRetList customFieldsList;


9. Every inventory item is handled differently in QuickBooks, so here will assume that all our items are InventoryItems. To handle different items please read my other article Quickbooks SDK: Step by Step guide to read Items using QBFC in C#

if (QBItemList.GetAt(i).ItemInventoryRet != null)
    IItemInventoryRet inventoryItem = QBItemList.GetAt(i).ItemInventoryRet;


10. We access our list of custom fields

customFieldsList = QBItemList.GetAt(i).ItemInventoryRet.DataExtRetList;


11. We iterate our list of custom fields and access the name value pairs and print it on the screen.

if (customFieldsList != null)
    for (int iCustomField = 0; iCustomField <= customFieldsList.Count - 1; iCustomField++)
    string fieldName = customFieldsList.GetAt(iCustomField).DataExtName.GetValue();
    string fieldValue = customFieldsList.GetAt(iCustomField).DataExtValue.GetValue();

If you like this, please share and like our page.

Author: Ahmad Faiq Ateel

By: Ahmad Faiq Ateel
Ahmad Faiq Ateel

Published: 2/23/2018