user2266878
user2266878

Reputation: 1

Quickbooks QBFC PurchaseOrderAdd

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`

Upvotes: 0

Views: 238

Answers (1)

GMan80013
GMan80013

Reputation: 536

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.

Upvotes: 1

Related Questions