如何使用 DIAPI C# 从 SAP B1 Add On 中删除销售订单行数据

How to Delete a Sales Order lines data From SAP B1 Add On using DIAPI C#

我想使用 c# 通过 Add On 从销售订单文档行部分中删除某些特定行。

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
}

我认为这很简单。

您需要先使用 DocEntry 获取要更改的文档。

然后您必须设置需要删除的行号。见下文

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());
}
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