Couple of words about commit. Why should we not put commit in middle of the process?

Quite simple – when we got an error after commit – we will have a garbage data, as system will only rollback changes made after commit before error.

NAV has internal auto commit function, which is called automatically at end of process. In 99.99(9) % of cases it is good enough. If you typed COMMIT inside your code you must have a strong reason for this, and I found in most cases there is no reason to put commit. Most common case is a page.runmodal(page::pageid, record), if this is run in middle of process – system will throw error, saying something like ‘The following C/AL functions can be used only to a limited degree during write transactions (because one or more tables are locked)”. Then it says “Use the COMMIT function to save the changes before this call, or structure the code differently.” which is completely misleading in my opinion. Only the second part of statement – ‘structure the code differently’ – is good, but commit in middle of process it is always risk, and generally bad practice.

So yep, it seems like with this error message MS encouraging us to use COMMIT in middle of process, which is entirely wrong, and again, if you use COMMIT inside a function – be prepared to explain why.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.