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

Notifications

Announcements

No record found.

Community site session details

Community site session details

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

Best/Optimal practice of using ttsBegin and ttsCommit

(0) ShareShare
ReportReport
Posted on by 2,114

Hi Techies,

I am looking for more clarity on this point, suppose we are updating more than 2,3 tables in class, what is the optimal way to use ttsBegin and ttsCommit for these transactions. Single ttsBegin, ttsCommit for all or one for every table transaction. In case of user interaction we should not include that in transaction, What if we don't have any such thing in between. 

Any response is appreciated.

Thanks,

I have the same question (0)
  • Verified answer
    Pete Alberts Profile Picture
    3,542 on at

    Hi Sangram

    I have pondered the same thing. A more senior developer commented that there are 2 factors to consider: performance and the actual logic behind the placement.

    Placing ttsbegin & ttscommit around a while statement that updates 10,000 records will be much more resource intensive than placing it inside the loop. So if the failure of one iteration does not mean the entire iteration should fall back, then one should place the ttsbegin & ttscommit statements inside the loop. However if it is crucial that all transactions finish successfully you'll have to place it around the while statement. The same logic can be applied if you have multiple statements modifying multiple tables.

    Mostly the second part governs my judgement of the placement of ttsbegin and ttscommit. If it is a very intensive job I will consider the performance impact (but I rarely get to that point). So in general I ask myself: "Should all changes should be reverted if an issue is encountered?"

    And then I don't understand what you mean with "user action". Which makes me wonder whether I am talking about the same thing. I am referring to batch jobs or any extensive piece of code.

  • Verified answer
    nmaenpaa Profile Picture
    101,160 Moderator on at

    Your tts scope should be determined by data integrity requirements.

    1) What should be rolled back if any part of my operation fails?

    2) Can other processes go wrong if only part of my changes are committed and others are still being processed by my class?

    If you have three transactions and the last one fails, the two other will stay.

    If all three operations are in one transaction, everything will be rolled back if there is an exception.

    Also, if you have three transactions, your first update is already visible and accessible to other users in the system, while the two other changes haven't yet been finished by your class.

  • Sangram Shinde Profile Picture
    2,114 on at

    Thanks pete, this is very helpful, User action means some dialog field or something where user allowed to add some action in between.

  • Sangram Shinde Profile Picture
    2,114 on at

    Thank you Nikolaos for descriptive explanation, this helps.

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 660 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 307 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans