on 01-06-2006 3:04 PM
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();
Hey Runar,
Is that your complete code you have posted? Maybe i am missing something but where do u assign the ItemCode property of the SAPbobsCOM.Document_Lines object? The only time I have received that error stating item no is missing is when I forgot to set that value or the itemcode no longer existed in the system.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
More info:
I have managed to isolate salesorders that raises the errors.
If I run the addon with a flag that those shall not be included, then it works ok.
But when trying to generate an invoice even from that single salesorder it raises the error.
But they don't look any different than the other salesorders, and I may even duplicate them, and then the duplicate generates fine.
If I generate an invoice manually from the sales order, it generates fine.
I'm at a loss here I am afraid... Anyone that has any idea what the error can be?
Hurray! 😄
After LOTS of tedious debugging, I finally found the answer!
And it looks like even the SDK-sample has it wrong! (05.OrderAndInvoice)
What finally brought me to the solution, was to delete one and one line from a sales-order until it was invoiced with my routine.
I had all the original linedata, and when the salesorder was invoiced, I could compare the line to the others, and What finally drew my attention, was a gap in RDR1.LineNum Linenumbering starts at 0, but Row 17 had LineNum 16, whereas Row 18 had LineNum 18. I guess this is what happens if someone deletes a row in the middle of the document.
So, the solution:
Replace this:
InvoiceLinesObject.BaseEntry = salesorder.DocEntry;
InvoiceLinesObject.BaseLine = t;
InvoiceLinesObject.BaseType = (int)SAPbobsCOM.BoObjectTypes.oOrders;
With this:
orderlines.SetCurrentLine(t);
InvoiceLinesObject.BaseEntry = salesorder.DocEntry;
InvoiceLinesObject.BaseLine = orderlines.LineNum;
InvoiceLinesObject.BaseType = (int)SAPbobsCOM.BoObjectTypes.oOrders;
And it will allways work. Using the incrementor to set the BaseLine is unsafe!
I hope this info will help someone. It certainly helped my day..
Hi Runar,
You should not use an incrementor to set a baseline number (if you are importing only specific lines). The baseline refers to the line number in the parent document. So you must specify which line number you want to create in your target doc (starting with line number 0 for the first line). Using the incrementor will work if you import all the lines of the base document starting with 0 to line.count - 1.
Barend Morkel wrote:
Using the incrementor will work if you import all the lines of the base document starting with 0 to line.count - 1
NO! That is exactly what I thought too, and even the SAP-example does it this way, but my routine WAS designed to import all of the lines of the base document, and it DIDN'T work, there was a gap in the linenum-series, I guess being a result from a row-deletion or something. I therefore say: NEVER base your routine on an incrementor, even if you are going to get all the lines!
This was also reported to SAP as a bug by our company. here is the response we received.
I'm sorry but this is a bug.
This issue will be fixed in a patch - please look for the Note Number
897479 in the "Info File.txt" in the patches.
EMAIL 2
========================================
Symptom
Using setCurrentLine in order to update or delete the row with the LineNum numerator will cuase the DI to update / remove the wrong row.
Other terms
DI API, update, delete, SetcurrentLine, visorder, remove, SAP Business One
Reason and Prerequisites
Bug
Solution
This issue will be fixed in a patch - please look for the Note Number in the "Info File.txt"
Until this patch is available there is a workaround available:
1. Use a DI recordset to look for the correct row
2. Use SetCurrentLine with the VisOrder numerator in order to point to the correct line
3. Ignore the data in the Lines Object and update the row with new data or remove the row
Sample project can be found at
User | Count |
---|---|
100 | |
11 | |
11 | |
6 | |
6 | |
5 | |
4 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.