
Hi. The default behavior in Business Central is to prevent you changing an order quantity is a sales order is associated. This makes no sense. It should instead allow you to sychronise the quantity to the purchase order if no shipment has occurred yet. I have found a raised event that allows you to have some influence - but it is unclear to be if I need to recreate all the other validations that would occur in the regular code or else break the system by saying isHandled = true.
My AL code is below:
[EventSubscriber(ObjectType::Table, Database::"Sales Line", 'OnBeforeCheckAssocPurchOrder', '', false, false)]
local procedure HandleOnBeforeCheckAssocPurchOrder(TheFieldCaption: Text[250]; var IsHandled: Boolean; var SalesLine: Record "Sales Line"; xSalesLine: Record "Sales Line")
var
PurchaseLine: Record "Purchase Line";
ContinueChangeQtyMsg: Label 'Do you want to change qty in associated PO?';
begin
If (SalesLine."Quantity (Base)" <> xSalesLine."Quantity (Base)") and (xSalesLine."Quantity (Base)" = xSalesLine."Outstanding Qty. (Base)") then begin
PurchaseLine.SetRange("Document No.", SalesLine."Purchase Order No.");
PurchaseLine.SetRange("Line No.", SalesLine."Purch. Order Line No.");
PurchaseLine.SetRange("Document Type", PurchaseLine."Document Type"::Order);
If PurchaseLine.FindFirst() and (PurchaseLine."Quantity (Base)" <> SalesLine."Quantity (Base)") then
If Dialog.Confirm(ContinueChangeQtyMsg) then begin
PurchaseLine.validate(Quantity, SalesLine.Quantity);
PurchaseLine.Modify();
IsHandled := true;
end;
//TODO Determine if we actually need to recreate additional checks and code to duplicate other checks performed by this function
end;
end; Hello,
If you think that this issue is caused by a bug, maybe you can file a support request to CSS and have us validate this in standard (assuming this is standard code).
Thanks.