Item - OnAfterGetRecord() CALCFIELDS(Inventory); CLEAR(ShortageDate); ShortageQty := Inventory; SalesLine.RESET; SalesLine.SETCURRENTKEY("Posting Date"); SalesLine.SETRANGE("Document Type",SalesLine."Document Type"::Order SalesLine.SETRANGE(Type,SalesLine.Type::Item); SalesLine.SETRANGE("No.",Item."No."); IF SalesLine.FIND('-') THEN REPEAT SalesLine.CALCFIELDS("Posting Date"); ShortageQty := ShortageQty - SalesLine."Outstanding Qty. (Base)"; IF ShortageQty < 0 THEN BEGIN ShortageDate := SalesLine."Posting Date"; SO := SalesLine."Document No."; END; UNTIL (SalesLine.NEXT = 0) OR (ShortageQty < 0);
Answers
I just show you an example code for guiding (it need to be refined a little bit if you want more complete result).
That being said, you code was great in solving the problem.