validate Quantity After Release

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);

You Can Write

Validate(Quantity,“Qty. to Ship” + “Quantity Shipped”);

[:^)]

…but this will not cancel your posted shipment and return the goods to the inventory.

Is it this standard functionality, you are looking for: “Posted Sales Shipment” → Functions → “Undo Shipment”?

I tried the

Validate(Quantity,“Qty. to Ship” + “Quantity Shipped”);

But without the ReOpen and Release you get the error

Status must be equal to ‘Open’ in Sales Header: Document Type=Order, No.=SO10215. Current Value is ‘Released’

I don’t want to cancel Posted shipments, I only want to change the quantity of items that were remaining to be of outstanding Qty - (Qty. to Ship + Qty shipped)

EX: The original Quantity is 5 at 10$ a piece. Once under 25$ the remaining order gets cancelled. So when the first pass goes to ship we only have 1 units, so Qty. to Ship becomes 1 and gets posted and backordered. The Outstanding Qty is then 4. Then we receive 2 more units and set the Qty. to Ship on that order to 2 and then posted. The cancel remaining line function happens since ((Outstanding Qty - “Qty to Ship”) * Unit Price ) <= 25$ before CodeUnit Sales-Post. The the function reopens the Sales Header and validates the Quantity to “Qty. to Ship” + “Quantity Shipped” , so it would validate the quantity to 3 (Qty. to Ship =2 + Quantity shipped =1). and then the order would release and then run COdeunit Sales-Post.RUN. Since Quantity is equal to Quantity shipped the Sales Header is done.

Suspend the Status Check before you validate Quantity

Salesline.SuspendStatusCheck(TRUE);

Thank you that solved my problem.