on 09-10-2008 5:33 AM
SBO version is 2005
Version PL5 of DIAPI
<WebMethod(EnableSession:=True, Description:="Test Function : Use this method to update Item Invoice. ")> _
Public Function ModifyItemOrder(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
Dim deleteLine As New Integer
Try
'Set Connection parametres- (System, DB Name, SBO id, SBO passowrd , DB ID, DB password)
SetConnectionParam("**")
'get data from web front.
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
'main statement for update
If oDocument.GetByKey(OrderDataSet.Tables("OrderHeader").Rows(0).Item("DocNum")) Then
If dtOrdHeader.Rows.Count > 0 Then
drOrdHeader = dtOrdHeader.Rows(0)
'Set values to the fields
oDocument.DocDueDate = drOrdHeader("DocDueDate")
oDocument.Address2 = drOrdHeader("Address2")
oDocument.Comments = drOrdHeader("Comments").ToString()
oDocument.HandWritten = SAPbobsCOM.BoYesNoEnum.tNO
End If
'count how many line in current line
deleteLine = oDocument.Lines.Count
If dtOrdLines.Rows.Count > 0 Then
Dim i As Integer
i = 0
'Add item into current document
While dtOrdLines.Rows.Count > i
oDocument.Lines.Add()
'strReturn = strReturn + "in while"
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.ItemDescription = drOrdLines("Desc").ToString()
oDocument.Lines.Price = drOrdLines("Uprice").ToString()
oDocument.Lines.Quantity = drOrdLines("Quantity").ToString()
i = i + 1
'strReturn = strReturn + "loop" + i.ToString()
End While
'Delete previous item
i = 0
While deleteLine > i
'set first row
oDocument.Lines.SetCurrentLine(0)
'delete first row
oDocument.Lines.Delete()
i = i + 1
End While
lngRetVal = oDocument.Update
'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
End If
Catch ex As Exception
Session("g_LastErrorMsg") = ex.Message
strReturn = ex.Message.ToString()
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
This is the method i have. After i have successfully update the sales order. SAP Business One 2005 display closed row for every product's row status i have in the sales order. Anybody know how to solve this? It should be Open row.
Regard,
Kean
Dear kean tan,
You could use SetCurrentLine(i) of Document_Lines when update line i.
Best Regards
Jane Jing
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Dear kean tan,
I saw the code to add document lines and delete document lines at the same time.
Could you try to update the lines directly but not add and delete the lines.
Best Regards
Jane Jing
SAP Business One
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
maybe
oDocument.Lines.Price = drOrdLines("Uprice").ToString()
oDocument.Lines.Quantity = drOrdLines("Quantity").ToString()
price and quantity are not string values, let them as double and check. If it doesnt help, try to run it in parts and check, what happens. Then add new parts and you must fiund, where is problem. I think, that you add items with zero quantity (di allows it) and sbo automatically close it.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
103 | |
12 | |
11 | |
6 | |
5 | |
4 | |
3 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.