cancel
Showing results for 
Search instead for 
Did you mean: 

Updating AP Invoice Question

Former Member
0 Kudos

Hi,

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")
            Inv.GetByKey(168)
            
            'Add a line to the Invoice
            InvLine = Inv.Lines
            System.Console.WriteLine("Count(1): " & CStr(InvLine.Count))
            InvLine.Add()
            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

Adrian

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Guys,

Thanks - Although not a solution to my problem (It would appear that this is a problem without solution) your answers have been very very useful. Will have to do the modification upstream before passing data into SAP B1 by the looks of things

Adrian

Former Member
0 Kudos

Adrian,

you are true, there is no easy solution for this - after adding invoice you can change only few fields with no link to GL and accounts.

If you need change some other field, which is not allowed to change after invoice is created, you should use oCorrectionInvoice object and change it with correction invoice.

Former Member
0 Kudos

Dear All,

The correction Invoice is CEE (CENTRAL EUROPE) specific stuff so do not offer for people from another localizations.

In other localizcations they must have to use credit memo

Regards,

Former Member
0 Kudos

Can u explain how we can solve by using credit memo

Former Member
0 Kudos

HI all,

see [;

for credit memo

this is sales process, replace document types with A/P

Regards

J.

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi Adrian,

U cannot update an invoice completly, just check from the standard SAP B1 screen.

We can update only the duedate, doc date, and remarks.. etc..

We cannot update the rowlevel information.

Dont forget to reward points.

Regards,

Vasu Natari.

Former Member
0 Kudos

Hi,

AP Invoice cannot be updated when it is added into the database.

(see B1 standard gui, when you add the AP Invoice you will get the same disclaimer!)

Regards

J.