user2240918
user2240918

Reputation: 31

How to get Customized template fields from invoice using QuickBooks QBFC

I want to get custom S.O. Invoice Template fields using QuickBooks QBFC.

Upvotes: 3

Views: 2023

Answers (2)

Paul Keister
Paul Keister

Reputation: 13077

Here's how to read custom fields from a sales order:

  1. Add "0" to the OwnerIDList of the SalesOrderQuery.
  2. Read custom header fields from the DataExtRetList that is attached to SalesOrderRet objects that are returned from the query.
  3. Read custom line item fields from the DataExtRetList in the SalesOrderLineRet and SalesOrderLineGrouptRet objects that are included in each SalesOrderRet (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.

Upvotes: 4

Nick Tiberi
Nick Tiberi

Reputation: 1141

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());
        }
    }

Upvotes: 2

Related Questions