I want to delete some of the particular lines from a sales order documents Lines part by Add On using c# .
Asked
Active
Viewed 5,769 times
3 Answers
1
You need to first get the document you want to alter using DocEntry.
You then have to set the line number that needs deletion. See below
Documents oDoc = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oOrders);
int docEntry = 109;
int lineNum = 2;
// Load your sales orders
if (oDoc.GetByKey(docEntry))
{
// Go through your line items
for (int i = 0; i < oDoc.Lines.Count; i++)
{
oDoc.Lines.SetCurrentLine(i);
if (oDoc.Lines.LineNum == lineNum) //Find your line number that you want delete.
{
oDoc.Lines.Delete(); //Delete
break;
}
}
// Update your sales order
if (oDoc.Update() != 0)
MessageBox.Show(oCompany.GetLastErrorDescription());
}

Kinyanjui Kamau
- 1,890
- 10
- 55
- 95
-
1This is usefull , its perfectly deletes the data . but which items i am deleting their details automatically comes to Document Discount. is there any solution for this ? – Nov 28 '19 at 13:20
-
1Please explain more about details coming to discount. – Kinyanjui Kamau Nov 28 '19 at 14:44
1
private void Delete_Single_Line_Row(string docentry, int lNum)
{
SAPbobsCOM.Documents oSalesOrd = null;
oSalesOrd = (SAPbobsCOM.Documents)SBOC_SAP.G_DI_Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oOrders);
int docEntry = Convert.ToInt32(docentry);
int lineNum = lNum;
// Load your sales orders
if (oSalesOrd.GetByKey(docEntry))
{
// Go through your line items
for (int i = 0; i < oSalesOrd.Lines.Count; i++)
{
oSalesOrd.Lines.SetCurrentLine(i);
if (oSalesOrd.Lines.LineNum == lineNum) //Find your line number that you want delete.
{
oSalesOrd.Lines.Delete(); //Delete
break;
}
}
// Update your sales order
int result = oSalesOrd.Update();
}
} enter code here
0
Documents oDoc = Utils.oCompany.GetBusinessObject(BoObjectTypes.oOrders);
oDoc.GetByKey(123);
oDoc.Lines.SetCurrentLine(0);
oDoc.Lines.Delete();
int lret = oDoc.Update();
if (lret != 0)
{
//HANDLE ERROR
}
This is pretty straight forward I think.

Vyron Paschalidis
- 209
- 1
- 8