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.
C/AL rollback without error
- Post published:October 17, 2014
- Post category:Uncategorized
- Post comments:4 Comments
- Reading time:1 mins read
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.
Thank you for a valuable tip! Is it considered the good code style though? Looks a liitle bit like a hack 🙂
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.
Is there any substitute for Asserterror? It is allowed only in test codeunit. At least for version 16.
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…