Hi guys, I have trouble creating an sales order. i have created a web service, data information are passed into this method but it did not process. Order is not created in database. Can anyone please help me with this?
Public Function CreateItemOrder2(ByVal OrderDataSet As DataSet) As String
Dim lngRetVal As Long
Dim strReturn As String = ""
Dim oDocument As SAPbobsCOM.Documents = Nothing
'Dim oUDF As SAPbobsCOM.UserFields
Dim dtOrdHeader As DataTable = Nothing
Dim dtOrdLines As DataTable = Nothing
Dim drOrdHeader As DataRow
Dim drOrdLines As DataRow
Dim oCompany As SAPbobsCOM.Company
Dim IngRow As Long = 0
Try
SetConnectionParam(***)
dtOrdHeader = OrderDataSet.Tables("OrderHeader")
dtOrdLines = OrderDataSet.Tables("ItemLines")
If ConnectToDatabase() Then
oCompany = Session("g_CompanyConnection")
oDocument = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oOrders)
oDocument.DocType = SAPbobsCOM.BoDocumentTypes.dDocument_Items
If dtOrdHeader.Rows.Count > 0 Then
drOrdHeader = dtOrdHeader.Rows(0)
'set values to the fields
'Set values to the fields
oDocument.CardCode = drOrdHeader("CardCode").ToString()
oDocument.DocDueDate = drOrdHeader("DocDueDate").ToString()
oDocument.Address2 = drOrdHeader("ShipTo").ToString()
oDocument.Address = drOrdHeader("BillTo").ToString()
oDocument.DocDate = Today
oDocument.NumAtCard = drOrdHeader("OrderType").ToString()
'oDocument.DocDate = Format(drOrdHeader("DocDate"), "yyyyMMdd")
oDocument.DocTotal = drOrdHeader("DocTotal").ToString()
oDocument.Comments = drOrdHeader("Comments").ToString()
oDocument.CardName = drOrdHeader("CardName").ToString()
oDocument.HandWritten = SAPbobsCOM.BoYesNoEnum.tNO
oUDF = oDocument.UserFields
oUDF.Fields.Item("U_Driver").Value = drOrdHeader,U_driver)
'oDocument.Lines.Add() 'auto add 1 row
lngRetVal = oDocument.Add
'Check the result
If lngRetVal = 0 Then
Session("g_LastErrorMsg") = " "
oCompany.GetNewObjectCode(strReturn) 'get last doc
Else
Session("g_LastErrorMsg") = oCompany.GetLastErrorDescription
End If
Else
Session("g_LastErrorMsg") = "No record found in data set"
End If
If dtOrdLines.Rows.Count > 0 Then
Dim i As Integer
i = 0
I suspect this while loop did not work at all..
While dtOrdLines.Rows.Count > i
drOrdLines = dtOrdLines.Rows(i)
'item lines - set value to the first line
oDocument.Lines.ItemCode = drOrdLines("ItemCode").ToString()
oDocument.Lines.LineTotal = drOrdLines("LineTotal").ToString()
oDocument.Lines.Desc = drOrdLines("Desc").ToString()
oDocument.Lines.Price = drOrdLines("Uprice").ToString()
oDocument.Lines.Quantity = drOrdLines("Quantity").ToString()
oDocument.Lines.Add()
i = i + 1
End While
lngRetVal = oDocument.Add
'Check the result
If lngRetVal = 0 Then
Session("g_LastErrorMsg") = " "
oCompany.GetNewObjectCode(strReturn) 'get last doc
Else
Session("g_LastErrorMsg") = oCompany.GetLastErrorDescription
End If
Else
Session("g_LastErrorMsg") = "No record found in data set"
End If
End If
Catch ex As Exception
Session("g_LastErrorMsg") = ex.Message
Finally 'no matter above is success or failed must execute this portion
oDocument = Nothing 'release the resource/obj variable
End Try
Return strReturn
End Function
Thank alot!
Kean