Skip to Content
0
Former Member
Jan 06, 2006 at 03:04 PM

The dreaded -5002

31 Views

I am creating invoices from sales-orders through the DI-API, and I get the -5002 error 😔

However, most of the invoices are created fine, but on some, I get:

Item no. is missing [INV1.ItemCode][line: 343]

And since it works on most invoices, the error is not because I have done 1 add() too much...

Does anyone know what I may have done wrong?

Here is my code:

rs.DoQuery("SELECT T0.DocEntry FROM ORDR T0 WHERE T0.CardCode = '17' AND T0.DocDueDate <= '01.31.06' AND T0.DocStatus <> 'C' AND T0.DocType = 'I' ORDER BY T0.DocNum");
if (rs.RecordCount != 0)
{
SAPbobsCOM.Documents InvoiceObject = (SAPbobsCOM.Documents)MainClass.SBOCompanyObject.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oInvoices);
MainClass.SBOCompanyObject.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oCreditNotes);
InvoiceObject.CardCode = bpName;
InvoiceObject.DocType = SAPbobsCOM.BoDocumentTypes.dDocument_Items;
SAPbobsCOM.Document_Lines InvoiceLinesObject = InvoiceObject.Lines;
while (rs.EoF == false)
{
int entry = (int)rs.Fields.Item("DocEntry").Value;
SAPbobsCOM.Documents salesorder = (SAPbobsCOM.Documents)MainClass.SBOCompanyObject.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oOrders);
salesorder.GetByKey(entry);
SAPbobsCOM.Document_Lines orderlines = salesorder.Lines;
for (int t = 0; t < orderlines.Count; t++)
{
InvoiceLinesObject.BaseEntry = salesorder.DocEntry;
InvoiceLinesObject.BaseLine = t;
InvoiceLinesObject.BaseType = (int)SAPbobsCOM.BoObjectTypes.oOrders;
if (t != orderlines.Count - 1)
{
InvoiceLinesObject.Add();
}
}
rs.MoveNext();
if (rs.EoF == false)
{
InvoiceLinesObject.Add();
}
}
int retVal = InvoiceObject.Add();