Ampersand
Ampersand

Reputation: 21

Adding Custom Field data to Quickbooks Invoices through QBFC in VB.net

I'm working on creating invoices in Quickbooks through QBFC. I'm having trouble adding Custom Field information to my InvoiceAdd request. I'm using the following code:

Dim CountryExt As IDataExtAdd = msgReq.AppendDataExtAddRq
CountryExt.DataExtName.SetValue("Country")
CountryExt.DataExtValue.SetValue("Spain")
CountryExt.OwnerID.SetValue(0)
CountryExt.ORListTxnWithMacro.TxnDataExtWithMacro.TxnDataExtType.SetValue(ENTxnDataExtType.tdetInvoice)                
CountryExt.ORListTxnWithMacro.TxnDataExtWithMacro.TxnID.SetValueUseMacro("TxnID:" & i)

The Add Request works perfectly for custom fields that do not have default values set by the customer, but causes an Index out of Range error when trying to overwrite a value that is set by the customer.

For example, if the Quickbooks Customer had the custom field 'Country' set to 'Portugal' the code would produce an invoice out of range error. However, if the Customer did not have a default 'Country' the code would set the 'Country' field on the invoice.

Do I need to add custom data through a second dataextmodrq after invoice creation, or am I missing some UnSet option?

Upvotes: 1

Views: 862

Answers (2)

Ampersand
Ampersand

Reputation: 21

Figured it out. You have to use a DataExtModRq after the invoice has been created and execute a second communication round with Quickbooks. Looks like Quickbooks does not allow you to set Custom Fields within the invoiceaddrq. The following code uses the response to the InoviceAddRequests to update the Country Field to Spain for all of the created invoices.

For i = 0 To invoiceAddResp.ResponseList.Count - 1
    If invoiceAddResp.ResponseList.GetAt(i).StatusCode <> 0 Then
    Check for failed entry here.
    Else
                Dim ExtInvoice As IInvoiceRet = invoiceAddResp.ResponseList.GetAt(i).Detail
                sessMgr.BeginSession("", ENOpenMode.omDontCare)
                Dim ExtReq = sessMgr.CreateMsgSetRequest("US", 12, 0)
                ExtReq.Attributes.OnError = ENRqOnError.roeContinue

                Dim DataExt As IDataExtMod = ExtReq.AppendDataExtModRq()
                DataExt.DataExtName.SetValue("Country")
                DataExt.DataExtValue.SetValue("Spain")
                DataExt.OwnerID.SetValue(0)
                DataExt.ORListTxn.TxnDataExt.TxnDataExtType.SetValue(ENTxnDataExtType.tdetInvoice)
                DataExt.ORListTxn.TxnDataExt.TxnID.SetValue(ExtInvoice.TxnID.GetValue)

                sessMgr.DoRequests(ExtReq)
                sessMgr.EndSession()
            End If
        Next

Upvotes: 1

Keith Palmer Jr.
Keith Palmer Jr.

Reputation: 27952

You didn't post enough code to really understand what you're doing, but what I assume you're doing is UPDATING an existing invoice.

If you are trying to UPDATE an existing invoice (and the custom fields on it) then you need to:

  1. To update an invoice, send a InvoiceModRq with no custom field data
  2. Send a separate DataExtModRq request to update any custom field values

You can not update the custom fields from directly within the InvoiceModRq.

You can reference the OSR which illustrates the supported fields for updating invoices.

Upvotes: 0

Related Questions