Run(codeunit) problem - Upgrade NF2.6 - 3.7

Hi folks, I have a potential problem with an upgrade. We currently have a NF2.01 database running on NF2.6 executables. I am keen on upgrading the executables to V3.7 to get the benefits of better stability and a much better debugger. I have run a test version without problems. However I have just been informed that there is a major change in V3.xx regarding the run(codeunit) function. I know that in V3.xx the RunWithCheck function is used in place of it but I didn’t know why. The help for run(codeunit) says: Use this function to load and execute the unit of C/AL code you specify. To use this function, you can specify a C/SIDE table associated with the codeunit when you defined the codeunit properties. This lets you pass a variable with the function. The transaction that the codeunit contains is always committed due to the boolean return value. The text in red is new in V3.xx. What this implies is that a V2.xx database running in V3.xx will have problems with rollback in functions where, say the ItemJnlPostLine function runs twice but fails on the second iteration. The initial transaction will have commited. So, my question is: Was there a fundamental change in this function from version 2 to 3 or is it safe to upgrade just the executables? I have seen dozens of sites running unmodified 2.xx databases in 3.xx and I am seriously worried that these are now potentially unsafe. Many thanks, Roy

Sorry to bring this back to the top but I’m still looking into the problem. I can’t actually recreate commit problems with a 2.6 database in 3.7 but I am still worried. Has anyone on the forum experienced problems with this or knows of any changes in the run(codeunit) function in 3.xx? Part of me thinks that the way it behaves now is the way it always has and all Navision did was document it in 3.xx

I think I agree with your suspicion that the 3.x change was a documentation change only. Here’s a fact that has not changed from v2.0 thru v4.0 – Fin.etx contains an error text that goes like this:


CodeUnit.Run() is allowed in write transactions only if the return value is not used. For example, ‘OK := CodeUnit.Run()’ is not allowed.

When you put this together with the quote from help you reference above, I get the following picture:

  • When CODEUNIT.RUN (or its cousin c.RUN) is called without using the return value, then a write transaction can be open when the codeunit is called, and any work done in the codeunit will become a part of the enclosing transaction. For example, Sales Post calls ItemJnlPostLine for each Sales Line where the type is Item – if any one of these item postings fails, the entire Sales Posting is rolled back.
  • When CODEUNIT.RUN (or its cousin) is called in a context that uses the boolean return value, then
    • No write transaction can be open at the time of the call.
    • If the call returns true, any work done in the codeunit will be committed automatically by the runtime
    • if the call returns false, any work done in the codeunit will be rolled back automatically by the runtime

Thank you Fritz, I’m glad you’ve said that. I had my suspicions and what you have said has confirmed them. To my mind the main change to ok := c.RunWithCheck() in V3 onwards was for dimensions handling rather than for any change in the executable. Cheers Roy

Hi folks, Can u please tell me, What is the procedure to become MBS Navision Ceritified Technical Professional?