cancel
Showing results for 
Search instead for 
Did you mean: 

Trying to create a Invoice based on Order need help Error -5002

Former Member
0 Kudos

the dreaded -5002 error is haunting me too! and I could not find a matching solution for this in the forum....

I need help quickly on this. I am trying to create invoices for some orders so the Base - Target relationship is retained. The orders I pick are all Open (DocStatus = O and the lines are all Open LineStatus = O)

here is my code


oInvoice.Lines.BaseEntry = 48
oInvoice.Lines.BaseLine = 0
oInvoice.Lines.BaseType = SAPbobsCOM.BoObjectTypes.oOrders
oInvoice.Lines.ItemCode = "A00001"
oInvoice.Lines.ItemDescription = "IBM Infoprint 1312"

'-----------------------------------
'adding Line
'-----------------------------------
oInvoice.Lines.Add

oInvoice.Lines.BaseEntry = 48
oInvoice.Lines.BaseLine = 1
oInvoice.Lines.BaseType = SAPbobsCOM.BoObjectTypes.oOrders
oInvoice.Lines.ItemCode = "A00002"
oInvoice.Lines.ItemDescription = "IBM Inforprint 1222"
           
'-----------------------------------
'adding Line
'-----------------------------------
oInvoice.Lines.Add

lRetCode = oInvoice.Add

If lRetCode <> 0 Then
    gObjCompany.GetLastError lErrCode, sErrMsg
    MsgBox (lErrCode & " " & sErrMsg)
End If

Accepted Solutions (1)

Accepted Solutions (1)

barend_morkel2
Active Contributor
0 Kudos

Indika,

Only set your base types...

(not items & description)

***********************

oInvoice.Lines.BaseEntry = 48

oInvoice.Lines.BaseLine = 0

oInvoice.Lines.BaseType = SAPbobsCOM.BoObjectTypes.oOrders

oInvoice.Lines.ItemCode = "A00001"

oInvoice.Lines.ItemDescription = "IBM Infoprint 1312"

'----


'adding Line (to fill the second item line)

' the 1st line item is there by default

'----


oInvoice.Lines.Add

oInvoice.Lines.BaseEntry = 48

oInvoice.Lines.BaseLine = 1

oInvoice.Lines.BaseType = SAPbobsCOM.BoObjectTypes.oOrders

oInvoice.Lines.ItemCode = "A00002"

oInvoice.Lines.ItemDescription = "IBM Inforprint 1222"

'----


'DO NOT Add THIS line

' (only if you want to add a 3rd line item)

'----


'''oInvoice.Lines.Add -> Don't add this

lRetCode = oInvoice.Add

If lRetCode <> 0 Then

gObjCompany.GetLastError lErrCode, sErrMsg

MsgBox (lErrCode & " " & sErrMsg)

End If

****************

remember to add :

oInvoice.CardCode = "your BP"

oInvoice.DocDueDate = Now

oInvoiceDoc.CardCode = txtDOCBPCode.Text

barend_morkel2
Active Contributor
0 Kudos

Indika,

(Sorry copy and paste error)

Only set your base types...

(not items & description)

***********************

oInvoice.Lines.BaseEntry = 48

oInvoice.Lines.BaseLine = 0

oInvoice.Lines.BaseType = SAPbobsCOM.BoObjectTypes.oOrders

'----


'adding Line (to fill the second item line)

' the 1st line item is there by default

'----


oInvoice.Lines.Add

oInvoice.Lines.BaseEntry = 48

oInvoice.Lines.BaseLine = 1

oInvoice.Lines.BaseType = SAPbobsCOM.BoObjectTypes.oOrders

'----


'DO NOT Add THIS line

' (only if you want to add a 3rd line item)

'----


'''oInvoice.Lines.Add -> Don't add this

lRetCode = oInvoice.Add

If lRetCode <> 0 Then

gObjCompany.GetLastError lErrCode, sErrMsg

MsgBox (lErrCode & " " & sErrMsg)

End If

****************

remember to add :

oInvoice.CardCode = "your BP"

oInvoice.DocDueDate = Now

oInvoiceDoc.CardCode = txtDOCBPCode.Text

Former Member
0 Kudos

Thanks for all these helps, I am restructuring the code as per tips and will let u know soon.

for information: the error -5002 contains the description of "-" .

Indika.

Former Member
0 Kudos

Barend,

Thanks for this, this helped me mostly. It was the last oInvoice.Lines.Add that was the culprit!

aparently the last line get added when you call oInvoice.Add (I don't understand the logic of that but.. )

However I did not have to set the BP Code or the due date for the invoice, Nor did I have to set the AccountCode as Fabio suggested.

with the BP Code, the Business Object picked up the Correct BP from the Order and the Due date was set to a default.

also the acctcode was set to what the RDR1 had in its acctcode (without me setting it)

Question: will there be instances that anyone of you are aware of, where the setting of any of those values become necessary?

Thanks,

Indika

FOA
Advisor
Advisor
0 Kudos

Hi Indika,

When you are creating an order that is related to a "Service" you will have to set the AccountCode property, as it's obligatory in this case.

Regards,

Felipe

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi,

i don't know exactly this error code (probably the error message can help me), but i'm not seeing the oInvoce.Lines.AccountCode property setting... for my knowledge this is a mandatory field for "document lines objects"

Hope this helps.

Kind regards,

Fabio Salucci