Trouble creating SalesOrder with Quickbooks and VB.Net

69 views Asked by At

I'm having trouble creating a sales order using QBFC15 and VB.Net into Quickbooks Enterprise 22. I can connect to QB and create a job for an existing customer with the following code:

Dim msgSetRs As IMsgSetResponse
Try
    sessManager = New QBSessionManagerClass()
    sessManager.OpenConnection("App", "Admin to Quickbooks Utility")
    sessManager.BeginSession("", ENOpenMode.omDontCare)
    Console.WriteLine("Quickbook COM Session Opened")
Catch
    Console.WriteLine("Quickbook COM Error: " + Err.Description)
    Return
End Try

Dim msgSetRq As IMsgSetRequest = sessManager.CreateMsgSetRequest("US", 15, 0)
msgSetRq.Attributes.OnError = ENRqOnError.roeContinue

Dim custAdd As ICustomerAdd = msgSetRq.AppendCustomerAddRq

custAdd.Name.SetValue(JobName)
custAdd.ParentRef.FullName.SetValue(String.Format("{0}", StoreName))
custAdd.BillAddress.Addr1.SetValue(String.Format("{0}", StoreName))
msgSetRs = sessManager.DoRequests(msgSetRq)

Note in the above, Storename = "MyStore.com" and Jobname = "Job - 1001"

When I try to create a sales order for that job, the code below does not give an error, but no sales order appears in QB.

I am reusing the same QBSession if that matters.

My subroutine's part to add a Sales Order

Dim requestMsgSet As IMsgSetRequest = sessManager.CreateMsgSetRequest("US",15,0)
requestMsgSet.Attributes.OnError = ENRqOnError.roeContinue

Dim SalesOrderAddRq As ISalesOrderAdd

SalesOrderAddRq = requestMsgSet.AppendSalesOrderAddRq()
SalesOrderAddRq.CustomerRef.FullName.SetValue(StoreName + ":" + JobName)
SalesOrderAddRq.TxnDate.SetValue(Date.Parse(OrderDate)) 'OrderDate is a DateTime = 3/9/2022 12:31:09 PM
SalesOrderAddRq.RefNumber.SetValue(MainOrderId.ToString) 'OrderID is an integer = 123456 
SalesOrderAddRq.BillAddress.Addr1.SetValue(StoreName)
SalesOrderAddRq.DueDate.SetValue(Date.Parse(OrderDate))

Dim SalesOrderAddLn As ISalesOrderLineAdd

SalesOrderAddLn = SalesOrderAddRq.ORSalesOrderLineAddList.Append.SalesOrderLineAdd

SalesOrderAddLn.ItemRef.FullName.SetValue("Merchandise")' This exists in QB item list
SalesOrderAddLn.Desc.SetValue("A Product")
SalesOrderAddLn.Amount.SetValue(10.00)

SalesOrderAddLn = SalesOrderAddRq.ORSalesOrderLineAddList.Append.SalesOrderLineAdd
SalesOrderAddLn.ItemRef.FullName.SetValue("Shipping")' This also in QB
SalesOrderAddLn.Desc.SetValue("Shipping")
SalesOrderAddLn.Amount.SetValue(12.00)

msgSetRs = sessManager.DoRequests(requestMsgSet)
Console.WriteLine("Quickbooks Sales Order Lines Created")
1

There are 1 answers

1
jjthebig1 On

Quickbooks returns success or failure in of the Response objects of the MessageSetResponse.ResponseList. So in your example, replace the last line in sales-order-creation method with the following to get the reason of the order not making it into QB.

Dim response As IResponse = msgSetRs.ReponseList.GetAt(0)
If response.StatusCode = 0 Then
  Console.WriteLine("Quickbooks Sales Order Lines Created")
Else
  Console.WriteLine("There was an error posting the sales order. " & response.StatusMessage)
End If

For the full list of QB status codes, see this page: https://developer.intuit.com/app/developer/qbdesktop/docs/develop/exploring-the-quickbooks-desktop-sdk/status-codes-in-response-messages

P.S. my VB skills is a bit rustic; please fix it as needed :)