I want to get custom S.O. Invoice Template fields using QuickBooks QBFC.
2 Answers
Here's how to read custom fields from a sales order:
- Add "0" to the
OwnerIDListof theSalesOrderQuery. - Read custom header fields from the
DataExtRetListthat is attached toSalesOrderRetobjects that are returned from the query. - Read custom line item fields from the
DataExtRetListin theSalesOrderLineRetandSalesOrderLineGrouptRetobjects that are included in eachSalesOrderRet(if you're reading line items).
If you're already using the IncludeRetElementList, you must add DataExtRet to the list; if you're not then don't start using IncludeRetElementList until you have custom fields working. Just like any transaction query, you won't see any line item data unless you set the IncludeLineItems flag in the request.
Custom fields are well documented in the QuickBooks SDK Manual. I'd recommend you take a look at the section DataExt: Using Custom Fields and Private Data in the QBSDK Programmers Guide.
- 12,851
- 5
- 46
- 75
-
sdk link broken – greg Dec 06 '22 at 12:42
To elaborate on Paul Keister's answer, the reason you must add "0" to the query is because that is the Owner ID of the custom field you are attempting to retrieve. 0 is probably likely to be the value, but if the owner ID is different, you will have to use a different value here.
Some example C# code:
//set the owner id of the custom field you are trying to get back
IInvoiceQuery invoiceQuery = requestMsgSet.AppendInvoiceQueryRq();
invoiceQuery.OwnerIDList.Add("0");
//set up query parameters and actually call your query...
//call this method for each invoice to get its custom fields (if they exist)
static void GetInvoiceCustomFields(IInvoiceRet invoice)
{
if (invoice.DataExtRetList == null)
{
return;
}
for (int i = 0; i < invoice.DataExtRetList.Count; i++)
{
IDataExtRet extData = invoice.DataExtRetList.GetAt(i);
Console.WriteLine("external data name: " + extData.DataExtName.GetValue());
Console.WriteLine("external data value: " + extData.DataExtValue.GetValue());
}
}
- 1,132
- 12
- 20