web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Unanswered

How to handle "TTSCOMMIT without first calling TTSBEGIN"

(0) ShareShare
ReportReport
Posted on by 596

Hi guys,

Is there a way to efficiently handle error : TTSCOMMIT without first calling TTSBEGIN ?

pastedimage1680615190861v1.png

I'm creating a class that processing SO-invoice-payment journal, which using custom table, which in its processing, will need certain update/insert processes for handling log, update statuses, etc.

It  happens sometime I'm hit this kind of error which is difficult to trace at which class or at line code this error hit. 

I'm trying to debug, but sometime found it and sometime it failed as well. 

Question : for this transactions, is there a way or special technique to resolve this kind of issue ? 

The way I'm doing is pretty simple, in section that I need to insert or update, I put this TTSBEGIN & TTSCOMMIT, I don't think there is some "un-pair" command for this, but the fact is the error arise. Perhaps some method to avoid this problem or maybe some procedure that make the system "auto-run" TTSBEGIN if he found TTSCOMMIT without it ? I'm not sure, but we live in era of AI, also this kind of error I've known this for quite sometime as well, with others developers as well, seems like common but hard to handle until now, just thinking out loud.

Thanks,

I have the same question (0)
  • Martin Dráb Profile Picture
    237,697 Most Valuable Professional on at
    RE: How to handle "TTSCOMMIT without first calling TTSBEGIN"

    There is no special technique - the only way is not having such a bug in code.

    I wouldn't say that it's common. I don't normally see this error, except of threads here when junior developers do bad things like trying to open a form inside a transaction.

  • Voltes Profile Picture
    596 on at
    RE: How to handle "TTSCOMMIT without first calling TTSBEGIN"

    Hi,

    What I mean "common" is firstly because I encounter this long time ago and it is still happened as of now, and the need of "identify" start and end of transaction block, is something quite tedious, and I can say it is obvious that could be or may be nowadays D365 F&O development team already find a way how to do it in their kernel or something.

    I mean, of course, if I want to insert or I want to update, please do TTSBEGIN and when I finish update/insert, please do TTSCOMMIT. Likewise, if there is no TTSBEGIN detected, please make necessary "Add" it. If I understand correctly, if there is error (catch error), doesn't it auto TTSABORT ? or is not ?

    Btw, I'm not open any other form, but to call other class like standard class such as SalesFormLetter, it's a yes. And like mentioned, I do think I'm already "pair" it all.

  • Martin Dráb Profile Picture
    237,697 Most Valuable Professional on at
    RE: How to handle "TTSCOMMIT without first calling TTSBEGIN"

    Maybe you should explain your particular case to use, because using ttsbegin/ttscommit doesn't sound that complicated to me. It should look like this:

    ttsbegin;
    
    // Your code. No return statement, not ttsabort, no forms.
    // And keep it simple. If you need a lot of code, wrap it into a method
    // and the method from here.
    
    ttscommit;

    The idea "when I finish update/insert, please do TTSCOMMIT" sounds nice, but it has a huge flaw. The system doesn't know when you're finished with all the operations that you want run together in a single transaction. That's what you need to specify, and you'll do it by ttscommit keyword.

  • Voltes Profile Picture
    596 on at
    RE: How to handle "TTSCOMMIT without first calling TTSBEGIN"

    Yeap, the main concept is quite simple, but the problem is when we already have such extended classes or re-use existing classes in other processes or perhaps to extend the current process, then it may happened we're using ttsbegin/ttscommit in layered.

    Actually the main problem is, if there is no "more efficient" way of doing this, can we at least know, at which class, at which method, it will be cool if the message can tell which line this error happened. The error message also mentioned stack trace, so it is nice if we're able to know easily what are the stacks, so we don't need to debug again. (talk about lazy, obviously) Because if only a simple code like the given sample, it is easy, but if classes after classes with several methods, I can say this is very tedious, and I agreed, this error is as simple and as basic as from older version AX, which it looks like something should already can be handled by system.

    Thanks,

  • Martin Dráb Profile Picture
    237,697 Most Valuable Professional on at
    RE: How to handle "TTSCOMMIT without first calling TTSBEGIN"

    Even in extensions, you should always use the pair of ttsbegin and ttscommit. If you put ttsbegin to one method and ttscommit to another, you're indeed asking for troubles. Don't do such things.

    Again, you can't expect the system to know which operations *you* want to run inside a single transaction. It's your decision.

    I'm not sure if the error uses error() method. If so, you can activate Monitoring and telemetry and see the stack trace in Application Insights. By the way, you can use Ideas to log feature requests. But of course, it can only tell you where the error was thrown, although the actual bug may be somewhere else.

  • Voltes Profile Picture
    596 on at
    RE: How to handle "TTSCOMMIT without first calling TTSBEGIN"

    Thank you and appreciate the advice. For the "pair" thing, yes it is certain I am pairing it in a single method, never cross my mind to make it separated across.

    About the telemetry, it may happens not all employee able to freely access Azure. So I wonder if there is some approach (of knowing the error or the stack) inside D365.

    Thanks

  • Voltes Profile Picture
    596 on at
    RE: How to handle "TTSCOMMIT without first calling TTSBEGIN"

    I have to revisited this issue, since I can't have access to Azure.

    Can we use this function appl.ttsLevel() instead ?

    does it help to identify what went wrong before ttscommit ? because the error is saying without first calling "ttsbegin", I'm thinking maybe that function can help then perhaps when it is detected, it will run ttsbegin first, does it make sense ?

    Thanks.

  • Martin Dráb Profile Picture
    237,697 Most Valuable Professional on at
    RE: How to handle "TTSCOMMIT without first calling TTSBEGIN"

    No, it won't magically solve the bug.

    ttsLevel will tell you that the transaction level is zero, which you already know, because the bug is that you're trying to commit a transaction when none was started. Starting the transaction at the point where you're trying to close it doesn't make sense. You should have started the transaction some time ago, but it might have been five or five thousand lines of code before.

    The whole idea is wrong - the system can't magically know which operations you meant to run as a single logically transaction. It's a question of business requirements analysis and implementation, not something that the runtime environment can automatically solve for you.

  • Voltes Profile Picture
    596 on at
    RE: How to handle "TTSCOMMIT without first calling TTSBEGIN"

    Ok, 1 last question, if we're using try..catch() and the process end up in catch for some exception error, is the ttsabort automatically called ?

    do we need to add ttsabort in our cacth error ?

    Thanks,

  • Martin Dráb Profile Picture
    237,697 Most Valuable Professional on at
    RE: How to handle "TTSCOMMIT without first calling TTSBEGIN"

    Throwing an exception does automatically abort a transaction. There is rarely a case when you should use ttsabort, because the right way is throwing an exception.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 683 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 563 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 398 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans