Hey fellas
Using the 2016 edition, I'm looking for a way to rollback transactions inside a try function if an error occurs - as would otherwise happen if an error occured in a piece of code.
Specifically I'm calling an XMLPort from a CodeUnit in a try function.
From the CodeUnit i call the XMLPort on an XML file.
Inside the XMLPort I import the fields into a temporary table and then transfer the values into a new Sales Header using validates.
If a validate is unsuccesful (throws an error) I would like for the changes to be rolled back.
Error or not, the calling CodeUnit should know what happened and rename the inputted XML file depending on whether it threw an error or not.
Hope you catch my drift and got any possible solutions.
Thanks in advance.
0
Answers
I would recommend restructuring the code, so you don't have to write it in a Try Function.
Instead I would make use of CODEUNIT.RUN to handle the errors, so it would look a bit more like this..
YourCodeunit.SetFileToImport(File);
IF YourCodeunit.RUN THEN
HandleSuccess(File)
ELSE
HandleError(File)
This way you can be sure the transaction is rolled back, if an error occurs.
It does not have to be inside Try function.
But generally I agree with nick_robo - ideally you should not need that function. The best would be to restructure the code so the system is left intact when an error occurs.
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
Thanks for the replies, guys.