Hi All
I have created an UDF on posted sales invoice line table to record total shipped quantity on each line (from sales shipment line table). Trying to update this field via a code unit and not sure which code unit and trigger to use. Someone else mentioned to use OnAfterInitFromSalesLine
but could not find it on "Sales-Post" codeunit. This is on BC SaaS 17.5
0
Answers
[EventSubscriber(ObjectType::Codeunit, 80, 'OnAfterSalesInvLineInsert', '', false, false)]
local procedure OnafterInsertliney(var SalesInvLine: Record "Sales Invoice Line")
var
salesline: Record "Sales Line";
begin
salesline.Reset();
Salesline.SetRange("Document Type", salesline."Document Type"::Order);
salesline.SetRange(Type, salesline.Type::Item);
salesline.SetRange("Document No.", SalesInvLine."Order No.");
salesline.SetRange("Line No.", SalesInvLine."Order Line No.");
if salesline.FindSet() then
repeat
SalesInvLine."UDF-01" := salesline.Quantity;
SalesInvLine."UDF-02" := salesline."Quantity Shipped";
SalesInvLine.Modify();
until SalesInvLine.Next() = 0;
end;
When populating custom fields, you are better off handing that in the OnbeforeInsert if possible. This eliminates the need for the second server round-trip. Reducing the number of server trips is a key factor in performance.