cancel
Showing results for 
Search instead for 
Did you mean: 

HELP !!!!

Former Member
0 Kudos

What is wrong here?

I got error - 2028 BaseDoc Missmatch.

Private Sub ConvertDO()


        Dim oGRPO As SAPbobsCOM.Documents
        Dim oRS As SAPbobsCOM.Recordset

        Dim sqlStr As String
        Dim i As Integer


        oDO = m_company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oDeliveryNotes)
        oRS = m_company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)

        sqlStr = "SELECT T0.DocEntry,T0.DocNum, T0.DocType FROM ODLN  T0 Where T0.DocStatus = 'O'"
        oRS.DoQuery(sqlStr)

        While Not (oRS.EoF)
            If oDO.GetByKey(oRS.Fields.Item("DocEntry").Value) Then
                '
                oGRPO = m_company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oInvoices)

                oGRPO.CardCode = oDO.CardCode

                oGRPO.DocDate = oDO.DocDate
                oGRPO.DocDueDate = oDO.DocDueDate
                oGRPO.DiscountPercent = oDO.DiscountPercent
                oGRPO.HandWritten = SAPbobsCOM.BoYesNoEnum.tYES
                oGRPO.DocNum = oDO.DocNum

                For i = 0 To oDO.Lines.Count - 1

                    oDO.Lines.SetCurrentLine(i)

                    oGRPO.Lines.ItemCode = oDO.Lines.ItemCode
                    oGRPO.Lines.Quantity = oDO.Lines.Quantity
                    oGRPO.Lines.WarehouseCode = oDO.Lines.WarehouseCode
                    oGRPO.Lines.Price = oDO.Lines.Price

                    oGRPO.Lines.BaseType = SAPbobsCOM.BoObjectTypes.oDeliveryNotes
                    oGRPO.Lines.BaseEntry = CInt(oRS.Fields.Item("DocNum").Value)  'oDraft.Lines.BaseEntry
                    oGRPO.Lines.BaseLine = oDO.Lines.LineNum

                    If i < oDO.Lines.Count - 1 Then
                        oGRPO.Lines.Add()
                    End If

                Next i

                'Add the GRPO
                lRetCode = oGRPO.Add
                If lRetCode <> 0 Then
                    m_company.GetLastError(lRetCode, sErrMsg)
                    MsgBox(lRetCode & "  " & sErrMsg)

                End If

            End If

            'Move to the next record
            oRS.MoveNext()
        End While

        MsgBox("Done")

    End Sub

Accepted Solutions (1)

Accepted Solutions (1)

jaccomoolenaar
Participant
0 Kudos

Hi Bruce,

A baseref always is made on docentry and not on docnum. I think that's your error.

Hope it helps,

Jacco

Answers (2)

Answers (2)

Former Member
0 Kudos

Thanks Guys,

Its works..

barend_morkel2
Active Contributor
0 Kudos

Hi Bruce,

If you are maikng use of the BASE functionality, you don't have to set up any other line data - this acts like the "draw document wizard in the client front end".

Thus cut the following from your code:

oGRPO.Lines.ItemCode = oDO.Lines.ItemCode

oGRPO.Lines.Quantity = oDO.Lines.Quantity

oGRPO.Lines.WarehouseCode = oDO.Lines.WarehouseCode

oGRPO.Lines.Price = oDO.Lines.Price

''''''AND''''''''

CInt(oRS.Fields.Item("DocNum").Value) is wrong,

seeing as the base entry must be the unique key of the parent document

(in your case oDO.GetByKey(oRS.Fields.Item("DocEntry").Value) would use the unique key to load the parent document - you must use that as the base entry)