codeunit 50001 SalesLineOperarions { trigger OnRun() begin end; procedure UpdateLines(DocNo: Text; DocType: Option; Zero: Boolean) var // Local var SalesLine: record "Sales Line"; ReleasesSalesLine: record "Sales Line"; BlanketReleaseQty: Integer; begin //Message('Updating Lines for Order no: %1, Doc Type: %2, Zero: %3', DocNo, DocType, Zero); // Loop thruugh all lines for this DocNo and Type where line is an item and Qty to ship is <> 0 SalesLine.SETRANGE("Document Type", DocType); SalesLine.SETRANGE("Document No.", DocNo); SalesLine.SETRANGE(Type, SalesLine.Type::Item); if Zero = true then begin SalesLine.SETFILTER(Quantity, '<>0'); end; IF SalesLine.FINDSET(TRUE) THEN REPEAT // Regular Orders // Validate record if (Zero = true) then // Message('Line: %1, Qty: %2, New Qty to Ship, %3', SalesLine."Line No.", SalesLine."Quantity", 0); SalesLine.VALIDATE("Qty. to Ship", 0) else // Message('Line: %1, Qty: %2, Qty Shipp::ed, %3, Qty Left: %4', SalesLine."Line No.", SalesLine."Quantity", SalesLine."Quantity Shipped", SalesLine."Quantity" - SalesLine."Quantity Shipped"); if (DocType = 1) then // Sales Order SalesLine.VALIDATE("Qty. to Ship", SalesLine."Quantity" - SalesLine."Quantity Shipped") else // Blanket begin // If it's a blanket find regular sales lines where Line.BlanketOrderNo = DocNo and line.BlanketLineNo = LineNo ReleasesSalesLine.SETRANGE("Document Type", 1); ReleasesSalesLine.SETRANGE("Blanket Order No.", DocNo); ReleasesSalesLine.SETRANGE("Blanket Order Line No.", SalesLine."Line No."); ReleasesSalesLine.SETRANGE(Type, SalesLine.Type::Item); BlanketReleaseQty := 0; // Iterate over all sales orders and find the total qty on sales orders (Qty Ordered: Don't care if it's shipped) IF ReleasesSalesLine.FINDSET(TRUE) THEN REPEAT BlanketReleaseQty := BlanketReleaseQty + ReleasesSalesLine.Quantity UNTIL ReleasesSalesLine.NEXT = 0; SalesLine.VALIDATE("Qty. to Ship", SalesLine."Quantity" - BlanketReleaseQty); end; // execute the OnModify() trigger SalesLine.MODIFY(TRUE); UNTIL SalesLine.NEXT = 0; end;
Answers
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
2. Try use decimal parameter (e.g. TestQty) instead of Zero - more flexible
SalesLine.SETFILTER(Quantity, '<>%1', TestQty);
SalesLine.VALIDATE("Qty. to Ship", TestQty)
3. Try to use ReleasesSalesLine.CALCSUMS(Quantity) with appropriate index change to avoid loop