Skip to Content
Former Member
Jul 29, 2008 at 01:39 PM

Updating AP Invoice Question



I am trying to write code to update an existing AP Invoice and cannot get it working. Basically the code I am using is:

Dim itemCode As String

            REM set the item code
            itemCode = "P-0004-SAP001-2" 'Not sure where to get this

            Dim Inv As SAPbobsCOM.Documents
            Dim InvLine As SAPbobsCOM.Document_Lines

            'Get Invoice Object
            Inv = vCmp.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oPurchaseInvoices)

            REM get the relevant invoice
            System.Console.WriteLine("Getting AP Invoice")
            'Add a line to the Invoice
            InvLine = Inv.Lines
            System.Console.WriteLine("Count(1): " & CStr(InvLine.Count))
            System.Console.WriteLine("Count(2): " & CStr(InvLine.Count))
            System.Console.WriteLine("Setting current line")
            InvLine.SetCurrentLine(InvLine.Count - 1)

            InvLine.ItemCode = itemCode
            InvLine.Quantity = 3
            InvLine.PriceAfterVAT = 666.0
            InvLine.TaxCode = "S"
            InvLine.VatGroup = "S"
            InvLine.Currency = "GBP"
            InvLine.ItemDescription = "This is an add item to existing test"
            'Add the Reserced Invoice
            retVal = Inv.Update()
            InvLine = Inv.Lines
            System.Console.WriteLine("Count(3): " & CStr(InvLine.Count))

            'Check the result
            If retVal <> 0 Then
                vCmp.GetLastError(ErrCode, ErrMsg)
                System.Console.WriteLine(ErrCode & " " & ErrMsg)
            End If

(Note: The System.Console.WriteLine... statements are just for debugging purposes)

The error I'm getting from this is:

ErrCode	-5002
ErrMsg	"Cannot add or update this document; rows are missing  [OPCH.DocNum][line: 0]"

Can someone explain what I am doing wrong or point me in the right direction.

Many thanks