How to cancel sales line in D365 F&O using X++



Sometimes in D365 Finance & Operations, we run into situations where we need to cancel a sales order line through code instead of manually doing it from the form. This usually comes up in automation scenarios, integrations or custom business processes.

Recently I had a requirement where a sales line needed to be cancelled using code. Instead of directly updating fields, I used the standard framework logic. In this post, I will share a simple and clean way to do it.

Implementation : Cancelling a Sales Line

In my case, I created a table extension for SalesLine and added a custom method that can be called whenever we need to cancel a specific line.

[ExtensionOf(tableStr(SalesLine))]
final class SalesLine_Extension
{
    public void gauCancelSalesOrderLine()
    {
        ttsbegin;
        this.selectForUpdate(true);
        SalesUpdateRemain::construct().updateDeliverRemainder(this, 0, 0);
        ttscommit;
    }
}

Comments