IF CODEUNIT.RUN THEN ...

nromainnromain Member Posts: 57
Hello,

To plug some linked treatments in job queue with no error message, i have create a codeunit that run an other codeunit such like this :



Codeunit 50000 (called by jobQueueEntry."parameter string" = 1)
IF CODEUNIT.RUN(50001,JobQueueEntry) THEN BEGIN
          FctWriteSuccessLog();
          JobQueueEntry."parameter string" := 2;
          IF CODEUNIT.RUN(50001,JobQueueEntry) THEN  //error
              FctWriteSuccessLog()
          ELSE
              FctWriteErrorLog();
     END ELSE
        FctWriteErrorLog();

My problem is that i receive an error message during the second run of the codeunit 50001 :

The following C/AL can be used only at a limited degree ... Use the COMMIT function ...

I first thought it comes from my var JobQueueEntry which i modified just before the codeunit.run but even if i don't modify it i still receive the error...
I have tried many different ways to do this (using var codeunit instead of codeunt.run, using temp var for modified jobQueueEntry,...) but still the error..

Could you help me please? it seems i can't do 2 "IF CODEUNIT.RUN THEN" in the same function...

Thanks

Nicolas

Answers

  • superjetsuperjet Member Posts: 40
    before the lines with IF CODEUNIT.RUN add COMMIT;
  • nromainnromain Member Posts: 57
    Thanks, it works :D but i don't understand why? what is the record that needs COMMIT?

    Nicolas
  • superjetsuperjet Member Posts: 40
    When the system enters a C/AL codeunit, it automatically enables write transactions to be performed. When the system exits a C/AL code module, it automatically ends the write transaction by committing the updates made by the C/AL code.

    This means that if you want the C/AL codeunit to perform a single write transaction, the system automatically handles it for you. However, if you want the C/AL codeunit to perform multiple write transactions, you must use the COMMIT function to end one write transaction before you can start the next. The COMMIT function separates write transactions in a C/AL code module.
Sign In or Register to comment.