November 16, 2013

Error: An unbalanced X++ TTSBEGIN/TTSCOMMIT pair has been detected.

Error: An unbalanced X++ TTSBEGIN/TTSCOMMIT pair has been detected.



Error:

When trying to create a new record(s) in any table system sows following error
eg. Sales Order and this error always appear.
clip_image001


Possible Reason(s):
TTS level '1' usually leaves your Ax session in an unusable state
that you can't close properly.
Check all code for form or class from where this error comes and count the ttsbegin and ttscommit there must be same like if u write 2 ttsbegin u must have to write 2 ttscommit.

Solution:
To resolve this error this TTS level should be ZERO, Run this job to get rid of that error, this job will find the tts level where its greater than zero and make it zero by calling TTSABORT.
static void TheAxaptaResetTTS(Args _args)
{
    while (appl.ttsLevel() > 0)
    {
        info(strfmt("Level %1 aborted",appl.ttsLevel()));
        ttsAbort;
    }
}


Other Info: 
ttsBegin: marks the beginning of a transaction. This ensures data integrity, and guarantees that all updates performed until the transaction ends (by ttsCommit or ttsAbort) are consistent (all or none).
ttsCommit: marks the successful end of a transaction. This ends and commits a transaction. MorphX guarantees that a committed transaction will be performed according to intentions.