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.

Vjeko

Vjeko has been writing code for living since 1995, and he has shared his knowledge and experience in presentations, articles, blogs, and elsewhere since 2002. Hopelessly curious, passionate about technology, avid language learner no matter human or computer.

This Post Has 4 Comments

  1. Kateryna Shneidmillier

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

    1. Vjeko

      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. Stefan Tomasevic

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

    1. Vjeko

      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