I am trying to write code on Sales Order's subform;
Quantity Remaining = Quantity - Quantity Shipped - Reserved Quantity
Quantity Remaining is a new field I added by extending the Sales Line table and Sales Order Subform.
This value will be Quantity - Quantity Shipped - Reserved Quantity
However, Quantity Shipped only gets a value once the SO is shipped with the value in Qty to Ship.
I tried writing the following code on ExtendedSalesLineTable
trigger OnModify()
var
begin
IF rec."Quantity Shipped" <> 0 then begin
recSalesLine.SetFilter("No.", Rec."No.");
recSalesLine.SetRange("Line No.", Rec."Line No.");
recSalesLine.SetFilter("Document No.", Rec."Document No.");
if recSalesLine.FindFirst() then begin
"Quantity Remaining" := (Rec.Quantity - Rec."Quantity Shipped") - rec."Reserved Quantity";
recSalesLine.Modify();
end;
end;
end;
The problem is, I get Not Available in Rec.Quantity Shipped hence it always show me new field Remaining Quantity as 0.
Answers
Also why don't you use for example a codeunit with eventsubscriber when table sales line is modified?