Hello,
I am creating a function that automatically cancels sales line if certain conditions are met (Ex Unshipped Inventory under a certain dollar amount gets automatically canceled). To do this I’m changing Quantity := “Qty. to Ship” + “Quantity Shipped” then I need to validate quantity. Since the Sales Header is already released I get an error. So I reopen the Sales Header before the function runs and then release after the function is done running. Is this a correct way to run this or should I create a new function in Sales Line that validates Quantity while being released.
This is what I currently have:
ReleaseSalesDoc.Reopen(SalesHeader);
WITH SalesLine2 DO BEGIN
SETRANGE(“Document Type”,SalesHeader.“Document Type”);
SETRANGE(“Sell-to Customer No.”,SalesHeader.“Sell-to Customer No.”);
SETRANGE(“Document No.”,SalesHeader.“No.”);
SETRANGE(Type,SalesLine.Type::Item);
SETRANGE(“Drop Shipment”,FALSE);
IF BlockLineCanceling THEN
SETRANGE(“Block Line Cancelling”,FALSE);
IF BlockBackOrders THEN BEGIN
SETRANGE(“Line No.”,SalesLine3.“Line No.”);
SETRANGE(“Block Back Orders”,TRUE);
END;
SETFILTER(“Outstanding Quantity”,’>%1’,0);
IF FINDFIRST THEN REPEAT
IF (“Outstanding Qty. (Base)”-“Qty. to Ship (Base)”) > 0 THEN BEGIN
Quantity := “Qty. to Ship” + “Quantity Shipped”;
Cancelled := TRUE;
VALIDATE(Quantity);
MODIFY;
END;
UNTIL NEXT = 0;
END;
ReleaseSalesDoc.RUN(SalesHeader);