C/AL rollback without error

If you want to rollback the database changes, but do not want the code execution to end, simply call ASSERTERROR ERROR(”); The ERROR(”) will quietly rollback the data changes, and the ASSERTERROR will capture the error, allowing the code execution to continue.

4 thoughts on “C/AL rollback without error”

  1. Thank you for a valuable tip! Is it considered the good code style though? Looks a liitle bit like a hack 🙂

    1. No, this is absolutely a hack! 🙂 Don’t do it at home, as long as home is Business Central, Microsoft won’t let your code be deployed if you do.

  2. Is there any substitute for Asserterror? It is allowed only in test codeunit. At least for version 16.

    1. No, there is no substitute as of yet. Microsoft might do something about at least allowing us to explicitly roll back and continue, but I wouldn’t hold my breath…

Leave a Reply