OnBeforeDeleteEvent not firing when Sales Line is deleted


I am trying to update Available Stock quantity based on the Sales Lines in Sales Order. When the Sales line is inserted or modified, the Available stock quantity field gets calculated correctly but when the sales line is deleted, the OnBeforeDeleteEvent or OnBeforeDelete are not triggering to calculate the Available Stock quantity field. Below is the code I have used to update the field when the Sales Line is deleted. Can anyone let me know why the delete event not triggered or anything wrong with the coding? Thanks and Regards.

  [EventSubscriber(ObjectType::Table, Database::"Sales Line", 'OnBeforeDeleteEvent', '', true, true)]

    local procedure OnBeforeDeleteEvent(var Rec: Record "Sales Line");

        ItemRec: Record Item;
        ItemRec.SetAutoCalcFields(Inventory, "Qty. on Sales Order");
        ItemRec.SetAutoCalcFields("Qty. on Purch. Order");
        ItemRec.SetRange("No.", Rec."No.");

        if ItemRec.FindSet(true, true) then begin

            ItemRec."Available Stock Qty_CRM" := ItemRec.Inventory + ItemRec."Qty. on Purch. Order" - ItemRec."Qty. on Sales Order";


Hi, I managed to resolve this problem. It works when I subscribe to OnAfterDeleteEvent

    //---this fires when Sales line is deleted
    [EventSubscriber(ObjectType::Table, Database::"Sales Line", 'OnAfterDeleteEvent', '', true, true)]

If you are only retrieving\updating 1 record, use a FINDFIRST and not FINDSET.

Correct! And turning on codecop analysis will show it as a warning/error.

Thanks for highlighting on that. I will correct it accordingly.