TempLines.SETFILTER(Status, 'Pending'); TempLines.SETFILTER("Ref Order Type", 'purchase'); TempLines.SETFILTER("Ref Order No", LinesToPost."Ref Order No"); //LinesToPost is an inparameter IF TempLines.FINDSET(TRUE, FALSE) THEN BEGIN REPEAT PurchLine.GET(PurchLine."Document Type"::Order, TempLines."Ref Order No", TempLines."Line No"); IF PurchLine."No." <> TempLines."Product Id" THEN ERROR('Error here'); PurchLine.VALIDATE("Qty. to Receive", TempLines."Qty Received"); PurchLine.MODIFY; //Is this needed after validate? TempLines.Status := TempLines.Status::Updated; IF TempLines."Processing Error" <> '' THEN TempLines."Processing Error" := ''; TempLines.MODIFY; COMMIT; UNTIL TempLines.NEXT = 0; END
Answers
Create a second variable (eg. TempLines2 ) that has exactly the same type as TempLines
Instead of updating TempLines, do:
You could also rewrite your code, and do it like in report 296 'Batch Post Sales Orders', using the 'IF Codeunit.RUN' construction.
//TempLines.Status := TempLines.Status::Updated;
TempLines..MARK;
...
TempLines.RESET;
TempLines.MARKEDONLY(TRUE);
TempLines.MODIFYALL(Status, TempLines.Status::Updated);
Lubost: Good thinking, but I can't be sure that all lines should have the status Updated. It is possible that an error is thrown in the loop, if that is the case, the status should not be updated to "Updated".
EDIT: Actually, It might work as you say, since it will not be marked unless it's supposed to be updated. Will test.
To clarify, I have a another codeunit calling this one to trap errors.
(Pseudo code)
Any other suggestions or ideas?