Try
Dim oST As SAPbobsCOM.StockTransfer = Nothing
Dim tmpDt2 As New Date
Dim cleanedDateString As String
Dim formattedDate As String
Dim DCDate As New Date
oST = __bobCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oStockTransfer)
oST.FromWarehouse = oForm.Items.Item("U_FromWH").Specific.Value & ""
oST.ToWarehouse = oForm.Items.Item("U_ToWH").Specific.Value & ""
tmpDt2 = DateTime.ParseExact(U_DocDate, GetDateFormat, DateTimeFormatInfo.InvariantInfo)
'Dim DocDate As SAPbouiCOM.EditText = oForm.Items.Item("U_DocDate").Specific
'tmpDt2 = DocDate.String
'tmpDt2 = DateTime.ParseExact(U_DocDate, GetDateFormat, DateTimeFormatInfo.InvariantInfo)
'cleanedDateString = DateString.Replace("#", "")
'DateTime.TryParse(cleanedDateString, DCDate)
'formattedDate = cleanedDateString
'DateTime.TryParseExact(formattedDate, "dd-MM-yyyy", "", DateTimeStyles.None, DCDate)
'formattedDate = DCDate.ToString("yyyyMMdd")
'' Dim DCDate As New Date
''DateTime.TryParseExact(tmpDt2, "yyyyMMdd", "", DateTimeStyles.None, DCDate)
formattedDate = tmpDt2.ToString("yyyyMMdd")
Dim serqry As String = ""
If oForm.Items.Item("U_FromWH").Specific.Value.ToString().StartsWith("P") Then
''''serqry = "select U_PDflSer Ser from OADM"
serqry = "SELECT U_Series FROM [@INVTSER] WHERE U_PostingPeriod = (SELECT Indicator FROM OFPR WHERE '" + tmpDt2 + "' BETWEEN F_RefDate AND T_RefDate) AND U_Branch= '5'" 'U_Location
Else
''''serqry = "select U_VDflSer Ser from OADM"
serqry = "Select U_Series FROM [@INVTSER] WHERE U_PostingPeriod = (Select Indicator FROM OFPR WHERE '" + formattedDate + "' BETWEEN F_RefDate AND T_RefDate) AND U_Branch= '3'" 'U_Location = '2'"
End If
Dim oRSSer As SAPbobsCOM.Recordset
oRSSer = __bobCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
oRSSer.DoQuery(serqry)
Try
'oST.Series = CInt(oRSSer.Fields.Item("Ser").Value.ToString())
oST.Series = CInt(oRSSer.Fields.Item("U_Series").Value.ToString())
Catch ex As Exception
End Try
oST.DocDate = tmpDt2
Try
oST.Comments = "Based On QC Transfer DocEntry : " & oForm.Items.Item("DocNum").Specific.Value
Catch ex As Exception
End Try
Dim SampQty As Double = 0.0
For iRow As Integer = 1 To mBTQ1.RowCount
If mBTQ1.Columns.Item("U_ItemCode").Cells.Item(iRow).Specific.Value & "" <> "" Then
If iRow <> 1 Then
oST.Lines.Add()
End If
oST.Lines.SetCurrentLine(iRow - 1)
oST.Lines.ItemCode = mBTQ1.Columns.Item("U_ItemCode").Cells.Item(iRow).Specific.Value & ""
oST.Lines.WarehouseCode = oForm.Items.Item("U_ToWH").Specific.Value & ""
oST.Lines.Quantity = CDbl(mBTQ1.Columns.Item("U_Quantity").Cells.Item(iRow).Specific.Value) '- CDbl(mBTQ1.Columns.Item("U_SampQty").Cells.Item(iRow).Specific.Value)
'If optSFG.Selected = True And (ComboValue = "Normal" Or ComboValue = "Retest") Then
' oST.Lines.Quantity = CDbl(mBTQ1.Columns.Item("U_Quantity").Cells.Item(iRow).Specific.Value) - CDbl(mBTQ1.Columns.Item("SmpQtyKg").Cells.Item(iRow).Specific.Value)
'Else
' '//B VC NLAG 28JAN2014 added code to set Quantity if QC Type is Transfer
' 'oST.Lines.Quantity = CDbl(mBTQ1.Columns.Item("U_Quantity").Cells.Item(iRow).Specific.Value) - CDbl(mBTQ1.Columns.Item("U_SampQty").Cells.Item(iRow).Specific.Value)
' If (ComboValue = "Transfer") Then
' '//reset values in sample qty
' mBTQ1.Columns.Item("SmpQtyKg").Cells.Item(iRow).Specific.Value = "0"
' mBTQ1.Columns.Item("U_SampQty").Cells.Item(iRow).Specific.Value = "0"
' '//set quantity
' oST.Lines.Quantity = CDbl(mBTQ1.Columns.Item("U_Quantity").Cells.Item(iRow).Specific.Value)
' Else
' oST.Lines.Quantity = CDbl(mBTQ1.Columns.Item("U_Quantity").Cells.Item(iRow).Specific.Value) - CDbl(mBTQ1.Columns.Item("U_SampQty").Cells.Item(iRow).Specific.Value)
' End If
' '//E VC NLAG 28JAN2014 added code to set Quantity if QC Type is Transfer
'End If
oST.Lines.BatchNumbers.Add()
oST.Lines.BatchNumbers.SetCurrentLine(0)
oST.Lines.BatchNumbers.BatchNumber = mBTQ1.Columns.Item("U_BatchNum").Cells.Item(iRow).Specific.Value
oST.Lines.BatchNumbers.Quantity = oST.Lines.Quantity
'If ComboValue = "Transfer" Then
' '//Update ItemGroup while Tranfer
' Dim dbsrc As SAPbouiCOM.DBDataSource = oForm.DataSources.DBDataSources.Item("@OBTQ")
' Dim oRs As SAPbobsCOM.Recordset = __bobCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
' oRs.DoQuery("Select ItmsGrpCod From OITM where ItemCode = '" & oST.Lines.ItemCode & "'")
' If oRs.RecordCount > 0 Then
' dbsrc.SetValue("U_ItmGrp", dbsrc.Offset, oRs.Fields.Item(0).Value)
' End If
'End If
End If '//If mBTQ1.Columns.Item("U_ItemCode").Cells.Item(iRow).Specific.Value & "" <> "" Then
Next '//For iRow As Integer = 1 To mBTQ1.RowCount
Dim RetVal As Integer = 0
Dim ErrorCode As Long = 0
Dim ErrorMessage As String = ""
'ErrorMessage = oST.GetAsXML()
RetVal = oST.Add()
If RetVal <> 0 Then
__bobCompany.GetLastError(ErrorCode, ErrorMessage)
__oApplication.MessageBox(ErrorCode & " " & ErrorMessage)
oForm.Freeze(False)
BubbleEvent = False
End If '//If RetVal <> 0 Then
Marshal.ReleaseComObject(oST)
oST = Nothing
Catch ex As Exception
getting error while using this code to add inventory transfer through DIAPI