on 02-16-2011 9:42 PM
Hi,
I am building an application which uses B1WS as it's interface to DISERVER. There is a situation I am confused about and am hoping the folks here can shed light on.
I have an order object, and I would like to delete a line item from it.
How can I do that?
Thank you,
Mike
Hi,
This appears to not be fully solved yet. Although the above code does remove the line item, when I try to add another line item to this order AFTER a line item has been deleted, SAP keeps throwing error -2035.
From looking in the forums, I am understanding that error 2035 has something to do with the tables keys being confused. I am not sure why this is happening. Could it be that if the order had 5 line items, then after this deletion it has 4, but SAP still thinks it has 5? And then when I add a line item, it thinks it ought to have 6 but only has 5?
Thank you
Mike
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ok, we figured it out. I wasn't updating the LineNum property after resetting the line items. The code below works for us, and hopefully for you too.
Again, the idea is, to delete a line item, create a new line items collection and put into it every line item EXCEPT the one you want to delete. Then update SAP.
private void DeleteLineFromOrder(string itemCode, string projectCode)
{
// Load SAP order via B1WS
string sessionID = B1WSLogin();
GetSAPOrder(docEntry, sessionID, out _order, out _document);
int oldLineItemCount = _document.DocumentLines.Count();
// Create collection of the current lineitems, before the add.
DocumentDocumentLine[] originalLineItems = _document.DocumentLines;
// Update the line item count
_document.DocumentLines = new DocumentDocumentLine[oldLineItemCount - 1];
int lineItemCounter = 0;
foreach (DocumentDocumentLine originalLineItem in originalLineItems)
{
if ((originalLineItem.ItemCode != itemCode) || (originalLineItem.ProjectCode != projectCode))
{
originalLineItem.LineNum = lineItemCounter;
_document.DocumentLines.SetValue(originalLineItem, lineItemCounter);
lineItemCounter++;
}
}
_order.Update(_document);
}
Cheers,
Mike
Cygnusoft, Inc.
Hi,
I figured it out. Here is the code:
private void DeleteLineFromOrder(string itemCode, string projectCode)
{
// Load SAP order via B1WS
string sessionID = B1WSLogin();
GetSAPOrder(docEntry, sessionID, out _order, out _document);
int oldLineItemCount = _document.DocumentLines.Count();
// Create collection of the current lineitems, before the add.
DocumentDocumentLine[] originalLineItems = _document.DocumentLines;
// Update the line item count
_document.DocumentLines = new DocumentDocumentLine[oldLineItemCount - 1];
int lineItemCounter = 0;
foreach (DocumentDocumentLine originalLineItem in originalLineItems)
{
if ((originalLineItem.ItemCode != itemCode) || (originalLineItem.ProjectCode != projectCode))
{
_document.DocumentLines.SetValue(originalLineItem, lineItemCounter);
lineItemCounter++;
}
}
_order.Update(_document);
}
Cheers,
Mike
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
98 | |
12 | |
10 | |
6 | |
6 | |
4 | |
3 | |
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.