I want to share with you situation I have faced where unexpected commit occurs. (Maybe it’s not a bug, and this is how Navision works. So commit was unexpected only for me
but anyway...
Nav sp3, SQL.
There is a form with button. In that’s button OnPush trigger I write a following code.
Repeatedly run report which changes some records. When first time report runs, I run it with request form, where user can enter a few parameters. After report has run, I take chose parameters and on next iterations (2nd , 3rd and so on) I run the same report without request form by passing chose parameters to report by function. (Another words – without user interaction).
Problem – looks like commit occurs after first iteration. For ex. If some records were changed after first iteration, but on second or next iterations occurred error – records which were changed on first iteration (when request form was shown) stays – not rolls back, but second and other iteration changes disappear – rollback works.
I hade to change my code and set parameters on the form (textboxes etc.) before running report. So I pass chose parameters to report by function and run report without request form. In this case everything works as it should, if error occurs all changes roll back.
“bad” Code example:
CLEAR(recCopy);
recCpy.COPY(Rec);
recCopy.FINDFIRST;
REPEAT
i += 1;
IF i = 1 THEN BEGIN
CLEAR(rep);
rep.RUNMODAL;
//Here commit occurs. Even if error appears on further iteractions chese changes stay.
rep.GetJournal(lcTempl, lcBatch);
END ELSE BEGIN
CLEAR(rep);
rep.USEREQUESTFORM(FALSE);
rep.SetJournal(lcTempl, lcBatch);
rep.RUNMODAL;
END;
UNTIL recCopy.NEXT = 0;
Question,
Do the same problem appears if I use “OK := Codeunit.RUN” instead of “rep.RUNMODAL” ?
Comments
IF CODEUNIT.RUN then does commit.
Independent Consultant/Developer
blog: https://dynamicsuser.net/nav/b/ara3n
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
Then, tell me why commit occurs only on the first iteration? If there is an error on second and other iterations, all changes roll back, but changes made after first iteration always stay.
When I run report without request form rep.USEREQUESTFORM(FALSE) and error occurs, then all changes stay unsaved.
I think, Navision after running RUNMODAL report with request form, finishes transaction and it does not matter if that report was run in a loop or etc.
BTW, if I lock table before running report I get standard Navision error that report.RUNMODAL and Ok:=CODEUNIT.RUN cannot be run in modify operations, and I must make commit or change programs structure.
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
Independent Consultant/Developer
blog: https://dynamicsuser.net/nav/b/ara3n
Barrier.CONSISTENT(FALSE);
This will cause any commit, including the implicit ones at the end of triggers to throw the huge error.
Just before you expect the COMMIT turn it off...
Barrier.CONSISTENT(TRUE);
You can also add these in a single instance codeunit:
Then use this to disable a commit sometimes.
IF FeelLikeIt THEN Barrier.SetBarrier(TRUE);
.
.
.
IF NOT Barrier.GetBarrier THEN COMMIT;
.
.
.
Barrier.SetBarrier(FALSE);
TVision Technology Ltd