Writing to SysException Log when You Have an Outer TTS Scope in Dynamics AX
A customer requested to have an error logged to the SysException table in Dynamics AX when the AIF process experienced an error. The caveat was they did not want the whole AIF process to abort due to this failure and roll back all of the changes for the import, just that one record. To achieve this they needed to capture the error and commit the error message into SysException log. The code still needed to track the failure to the test so it could roll back that change and move on to the next object in the list and continue to process.
Because this code was inside an outer TTS scope, anytime they tried to write the exception to the database it rolled back the exception log due to the failure. To resolve this they needed to add an additional TTS level, but that caused to have a TTS level greater than 1.
To resolve that it was necessary to call the setConnection method and pass in the userConnection. This allowed it to create its own scope for the transaction, commit the insert into the SysException log, and still roll back the changes from the error AIF import object.