Need explanation of the error

ReedbergReedberg Member Posts: 68
Hello all!

I have a report with such code:
IF ErrorHandlingG = ErrorHandlingG::"Skip error" THEN BEGIN
  IF NOT CallUpdateItemG.RUN(Item) THEN BEGIN
    IsErrorG := TRUE;
    ControlPanelTempG."No. of Errors" := ControlPanelTempG."No. of Errors" + 1;
    CurrReport.SKIP;
  END;
END ELSE
  CallUpdateItemG.RUN(Item);
When I run rhis report from Object Designer it works just fine if ErrorHandlingG = "Skip error" or "Break on error". When I run this report from another form (Job Batch) and ErrorHandlingG = "Break on error" it also works fine. When ErrorHandlingG = "Skip error" I got this error message:
The following C/AL functions can be used only to a limited degree during write transactions (because one or more tables will be locked).
Report.RunModal() is allowed in write transactions only if 'RequestForm = FALSE'. For example, 'Report.RunModal(...,FALSE)' is allowed
I know I can put COMMIT before running CallUpdateItemG codeunit, I tried it and it works. But it doesn't fit me. I want to understand, why
CallUpdateItemG.RUN(Item) - doesn't cause an error
IF CallUpdateItemG.RUN(Item) causes an error.
What is the difference?

P.S.:
I already searched the forum and found this post very usefull: http://www.mibuso.com/forum/viewtopic.php?t=38919&f=23
However it doesn't describe why error occurs if I handle boolean return value of RUN(Codeunit).

Thanks!

Answers

  • vaprogvaprog Member Posts: 1,141
    Well, superjet's last post actually explains it pretty well.
    In NAV there is at most one write transaction.
    If NAV allowed your 2nd codeunit.RUN it needed to start a 2nd, nested, transaction just before the call in order to roll back to this point in case something goes wrong within that 2nd RUN. The first call to codeunit.RUN (within Job Queue Dispatcher) could still succeed and therefore should not be rolled back. This is only possible with nested write transactions and therefore, this situation cannot be handled by NAV.
  • ReedbergReedberg Member Posts: 68
    vaprog,
    Thanks!
Sign In or Register to comment.