For me these two event subscribers are ok:
[EventSubscriber(ObjectType::Table, Database::"Sales Line", 'OnAfterValidateEvent', 'Quantity', false, false)]
local procedure QtyChange(var Rec: Record "Sales Line")
begin
Rec.TotalCost := Rec."Unit Cost" * Rec.Quantity;
end;
[EventSubscriber(ObjectType::Table, Database::"Sales Line", 'OnAfterValidateEvent', 'Unit Price', false, false)]
local procedure UnitPriceChange(var Rec: Record "Sales Line")
begin
If (Rec."Unit Price" > 0) then Rec.Margin := ((Rec."Unit Price" - Rec."Unit Cost") / Rec."Unit Price") * 100;
end;
Here you're handling the customization at table level (subscribing to a standard event) and this is the best approach. Why for Unit Cost you've subscribed a Page event and not the table's event as the other field?