Search code examples
apilineacumaticaerp

Acumatica API - Delete Sales Order Lines


I want to delete all sales order lines by given OrderNbr and then insert new sales order lines using the same Sales Order Number. This will be done only for Sales order in 'Open' or 'Credit Hold' status and whenever the order line has not been shipped of course.

How can I get the lines row count and go through each one to delete then? How can I use the SO301000.DocumentDetails.ServiceCommands.DeleteRow?


Solution

  • I think you should use something like:

    var commands = new List<Command>
    {
        new Value { LinkedCommand = SO301000.OrderSummary.OrderType, Value = "SO"},
        new Value { LinkedCommand = SO301000.OrderSummary.OrderNbr, Value = "XXXXXX"},
    
        SO301000.DocumentDetails.ServiceCommands.RowNumber,
        SO301000.DocumentDetails.OrderType,
        SO301000.DocumentDetails.OrderNbr,
        SO301000.DocumentDetails.LineNbr,
        SO301000.DocumentDetails.InventoryID,
        SO301000.DocumentDetails.Quantity,
    };
    
    var content = context.SO301000Submit(commands.ToArray());

    Then loop through "content" which is now a list of all the rows in your sales order and do a SO301000.DocumentDetails.ServiceCommands.DeleteRow to get rid of them.