0

I have been working on a quickbooks project and have been successful on many aspects until I hit a wall at attempting to add a Purchase Order.

as the title states I am using the QBFC -has anyone successfully accomplished this and could point me in the right direction ?

I am currently using mostly example code from the OnScreen reference from quickbooks ( before customizing it) a process which I have used for the other aspects of what I already have working...

It runs fine, but currenrtly doesn't actally add anything to the Quickbooks vendor?

thanks in advance

` Public Sub writePO_ToQB()

    Dim sessManager As QBSessionManager
    Dim msgSetRs As IMsgSetResponse

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

    MessageBox.Show("calling write command")
    writeActualQBMSG(msgSetRq)

    'step3: begin QB session and send the request
    sessManager.OpenConnection("App", "DataBridge JBOOKS")
    sessManager.BeginSession("", ENOpenMode.omDontCare)
    msgSetRs = sessManager.DoRequests(msgSetRq)



End Sub

Public Sub writeActualQBMSG(requestMsgSet As IMsgSetRequest)

    '   Dim requestMsgSet As IMsgSetRequest
    Dim PurchaseOrderAddRq As IPurchaseOrderAdd
    PurchaseOrderAddRq = requestMsgSet.AppendPurchaseOrderAddRq()

    'add all the elements of a PO to the request - need to determine what is required!!

    '  PurchaseOrderAddRq.VendorRef.FullName.SetValue("Test Vendor")
    PurchaseOrderAddRq.VendorRef.ListID.SetValue("80000094-1512152428")






    '------------------- CODE FROM QBS --------
    Dim ORInventorySiteORShipToEntityElementType162 As String
    ORInventorySiteORShipToEntityElementType162 = "InventorySiteRef"
    If (ORInventorySiteORShipToEntityElementType162 = "InventorySiteRef") Then
        'Set field value for ListID
        PurchaseOrderAddRq.ORInventorySiteORShipToEntity.InventorySiteRef.ListID.SetValue("200000-1011023419")
        'Set field value for FullName
        PurchaseOrderAddRq.ORInventorySiteORShipToEntity.InventorySiteRef.FullName.SetValue("ab")
    End If
    If (ORInventorySiteORShipToEntityElementType162 = "ShipToEntityRef") Then
        'Set field value for ListID
        PurchaseOrderAddRq.ORInventorySiteORShipToEntity.ShipToEntityRef.ListID.SetValue("200000-1011023419")
        'Set field value for FullName
        PurchaseOrderAddRq.ORInventorySiteORShipToEntity.ShipToEntityRef.FullName.SetValue("ab")
    End If
    ' ----------------- END OF CODE FROM QBS --------------------------------------------

    '------------ MOR QBS CODE ------------

    Dim ORPurchaseOrderLineAddListElement324 As IORPurchaseOrderLineAdd
    ORPurchaseOrderLineAddListElement324 = PurchaseOrderAddRq.ORPurchaseOrderLineAddList.Append()
    Dim ORPurchaseOrderLineAddListElementType325 As String
    ORPurchaseOrderLineAddListElementType325 = "PurchaseOrderLineAdd"
    If (ORPurchaseOrderLineAddListElementType325 = "PurchaseOrderLineAdd") Then
        'Set field value for ListID
        '  ORPurchaseOrderLineAddListElement324.PurchaseOrderLineAdd.ItemRef.ListID.SetValue("200000-1011023419")
        'Set field value for FullName
        ORPurchaseOrderLineAddListElement324.PurchaseOrderLineAdd.ItemRef.FullName.SetValue("granite")
        'Set field value for ManufacturerPartNumber
        ORPurchaseOrderLineAddListElement324.PurchaseOrderLineAdd.ManufacturerPartNumber.SetValue("123456789")
        'Set field value for Desc
        '   ORPurchaseOrderLineAddListElement324.PurchaseOrderLineAdd.Desc.SetValue("ab")
        'Set field value for Quantity
        ORPurchaseOrderLineAddListElement324.PurchaseOrderLineAdd.Quantity.SetValue(2)

        Dim DataExt326 As IDataExt
        DataExt326 = ORPurchaseOrderLineAddListElement324.PurchaseOrderLineAdd.DataExtList.Append()
        'Set field value for OwnerID
        ' DataExt326.OwnerID.SetValue(System.Guid.NewGuid().ToString())
        DataExt326.OwnerID.SetValue(0)
        'Set field value for DataExtName
        DataExt326.DataExtName.SetValue("ab")
        'Set field value for DataExtValue
        DataExt326.DataExtValue.SetValue("ab")
    End If
    If (ORPurchaseOrderLineAddListElementType325 = "PurchaseOrderLineGroupAdd") Then
        'Set field value for ListID
        ORPurchaseOrderLineAddListElement324.PurchaseOrderLineGroupAdd.ItemGroupRef.ListID.SetValue("200000-1011023419")
        'Set field value for FullName
        ORPurchaseOrderLineAddListElement324.PurchaseOrderLineGroupAdd.ItemGroupRef.FullName.SetValue("ab")
        'Set field value for Quantity
        ORPurchaseOrderLineAddListElement324.PurchaseOrderLineGroupAdd.Quantity.SetValue(2)
        'Set field value for UnitOfMeasure
        ORPurchaseOrderLineAddListElement324.PurchaseOrderLineGroupAdd.UnitOfMeasure.SetValue("ab")
        'Set field value for ListID
        ORPurchaseOrderLineAddListElement324.PurchaseOrderLineGroupAdd.InventorySiteLocationRef.ListID.SetValue("200000-1011023419")
        'Set field value for FullName
        ORPurchaseOrderLineAddListElement324.PurchaseOrderLineGroupAdd.InventorySiteLocationRef.FullName.SetValue("ab")
        Dim DataExt327 As IDataExt
        DataExt327 = ORPurchaseOrderLineAddListElement324.PurchaseOrderLineGroupAdd.DataExtList.Append()
        'Set field value for OwnerID
        DataExt327.OwnerID.SetValue(System.Guid.NewGuid().ToString())
        'Set field value for DataExtName
        DataExt327.DataExtName.SetValue("ab")
        'Set field value for DataExtValue
        DataExt327.DataExtValue.SetValue("ab")
    End If

    ' ----- END OF MORE QBS CODE ----------

End Sub`

1 Answers1

1

The issue here is you have not included the error and response handling code. You need to have something equivalent to the WalkPurchaseOrderAddRs(responseMsgSet). Specifically within that function this checks for error conditions. I have a modified version of their sample.

For j=0 To responseList.Count - 1
   Dim response As IResponse
   response = responseList.GetAt(i)
   'check the status code of the response
   If response.StatusCode = 0 Then
      '  response is ok, handle results as usual... 

   ElseIf response.StatusCode = 1 Then 
      '  Used when search results return nothing...

   Else '  > 1  Is an error      
      '  Is an error or warning condition...  
      '   Capture code and message from QuickBooks

      Dim code As String = response.StatusCode
      Dim severity As String = response.StatusSeverity '  ERROR or WARNING
      Dim message As String = response.StatusMessage

   End If
Next j

As a side note, the OSR sample code really is just for illustration purposes. This and similar code is pointless.

Dim ORInventorySiteORShipToEntityElementType162 As String
ORInventorySiteORShipToEntityElementType162 = "InventorySiteRef"
If (ORInventorySiteORShipToEntityElementType162 = "InventorySiteRef") Then

One more hint. When you are setting values from lists like Vendor or ItemRef, you can choose the ListID or the FullName. If you use both as the sample shows then the ListID is used by QuickBooks. I recommend you use the FullName and scrap the ListID. The reason is QuickBooks will parrot whatever you use back to you in an error message. So if your vendor doesn't exist you will either see something like "missing element 80000094-1512152428" or "missing element TheFullName" which is cryptic but readable.

Ok, one more... The sample code that appears to set the custom field data DataExt... will not work. You need to use the DataExtAdd request instead.

GMan80013
  • 536
  • 4
  • 13
  • thanks - Yeah I know the sample code is pretty much useless in most cases ( I have already worked with successfully Adding / Modifying / querying Vendors, Customers( at multiple levels as I integerate a Customer and job from a different system) etc... this PO piece is just throwing me for a look for some reason! the only thing that is still hanging me up ( hopefully) is the last thing you mentioed... the DataEXT piece, I canot seem to figure out what you meant there, and cannot get that working I keep getting an error it cannot be found - – user2266878 Feb 12 '18 at 03:35
  • forget previous comment - figured it out -Thanks so much! I had previously gotten Vendors, and multi level customers working for previous integeration work so I knew the sample code is pretty useless and what not - PO's were just throwing me for a loop for some reason! - great hint on the Values, I had figured that out previously but definitely wasted a lot of time on that issue at one point! I do believe though most of the modify functionality you need to actually use the ListID, at least it required me to for something previous. – user2266878 Feb 12 '18 at 03:42
  • Please implement the error handling. It is well worth your effort. QuickBooks will tell you what is wrong. You don't have to waste any time. Since you figured it out, what was wrong? – GMan80013 Feb 12 '18 at 03:49
  • I did add error checking - both to this issue and the rest of my code for QB's incase I have issues! thanks for the tip - the issue was simply some of the required fields not having valid data going in to Qbs – user2266878 Feb 13 '18 at 04:27
  • @user2266878, don't forget to upvote the answer if it helped you. ;) lol – jjthebig1 Sep 17 '21 at 14:31