Skip to Content

SDK - Delete Row with DocEntry and LineNum as parameters

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

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Sep 29, 2017 at 04:08 PM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • Oct 02, 2017 at 08:10 AM

    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

    Add comment
    10|10000 characters needed characters exceeded