Skip to Content
0

SDK - Delete Row with DocEntry and LineNum as parameters

Sep 29, 2017 at 03:57 PM

93

avatar image
Former Member

Hi Guys,

Can anyone help with my question, I would like the SDK code to delete a row from a sales order but I need to specify the DocEntry and LineNum of the sales order row to be deleted.

How would I go about this?

Thank you,

Jordan

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

DIEGO LOTHER Sep 29, 2017 at 04:08 PM
0

Hi Jordan

This should do the work:

Documents oDoc = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oOrders);
int docEntry = 190;
int lineNum = 0;
//load your sales orders
if (oDoc.GetByKey(docEntry))
{
    //Walk through your line itens
    for (int i = 0; i < oDoc.Lines.Count; i++)
    {
        oDoc.Lines.SetCurrentLine(i);
        if (oDoc.Lines.LineNum == lineNum) //Find your line num that you want delete.
        {
            oDoc.Lines.Delete(); //Delete
            break;
        }
    }

    //Update your sales order
    if (oDoc.Update() != 0)
        MessageBox.Show(oCompany.GetLastErrorDescription());
}

Hope it helps.

Kind Regards,

Diego Lother

Share
10 |10000 characters needed characters left characters exceeded
Edy Simon Oct 02, 2017 at 08:10 AM
0

Hi Jordan,

Diego's answer should work well.
Just another option,
The DocumentLines.SetCurrentLine accepts fields value from 'RDR1.VisOrder'
So the sample without looping the doc.Lines object would be:

oRS.DoQuery("SELECT VisOrder FROM RDR1 WHERE DocEntry = 1 and LineNum in (1,5,7,9) ORDER BY VisOrder DESC")
for(int i=0; i<oRS.RecordCount;i++) { int visOrder = (int)oRS.Fields.Item("VisOrder").Value;
doc.Lines.SetCurrentLine(visOrder);
doc.Lines.Delete(); oRS.MoveNext();
}
int errCode = oDoc.Update();

Caution when you want to remove multiple lines at once, loop from the last VisOrder in desc order.
The sample above would delete lines 1,5,7 and 9 from Order with DocEntry = 1

Regards
Edy

Share
10 |10000 characters needed characters left characters exceeded