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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

How to solve the issue of multiple users doing the same logic on a record at the same time?

(0) ShareShare
ReportReport
Posted on by 1,552

If i create a button that inserts records in a certain table when clicked. And i put the insert code inside a ttsbegin and ttscommit. Let's say 6 users clicked the same button at the same time. Does the ttsbegin and ttscommit make the other users wait until each user finishes or a deadlock will happen and what to do in order to avoid such error? 

I have the same question (0)
  • zhifeng Profile Picture
    Microsoft Employee on at

    Would you please share more details about the customization? Are these 6 users touch same records or different records? 

  • junior AX Profile Picture
    1,552 on at

    Let's say a button when you click it, it creates a new record by code in custTable with certain info. So they touch the same button

  • Suggested answer
    Sergei Minozhenko Profile Picture
    23,095 on at

    Hi Junior Ax,

    Updates and deletes are controlled by the kernel and if multiple users edit or delete the same records, one of them gets an error message if another already performed action. Also, there is a locking mechanism on the SQL side that locks record if the update process already started. For new records, there is no such control, except unique indexes or custom code. In the case of customer creation, if 6 users press creates button 6 times - 6 customers will be created in case if you use number sequence for the customer form. If the account number is entered manually and users will enter the same account number, only one will be created and others will trigger errors.

  • Suggested answer
    nmaenpaa Profile Picture
    101,172 Moderator on at

    If your button creates a new record, then every user is actually working on their own separate (new) records. So there's no conflict, and everyone's transaction will succeed (assuming there's no duplicate Customer Id in the records).

    If many users are really working on the same record, the system prevents conflicting changes to it. When record is selected for update, the system checks RecVersion of the record. When the actual update() is triggered, the system checks again, and if RecVersion was changed in the database meanwhile, an update conflict is raised and you can't update the record from your session. Instead you first need to refresh it. User will see error message like "One or more users updated the record, the values on the screen might not be  up to date. Please refresh and try again".

  • Suggested answer
    Leo Chen Profile Picture
    Microsoft Employee on at

    Agree with Nikolaos but just add some screenshots - There will be no conflict for multiple Inserts in same time. However for update/delete against same record, you'll see success messasge for the exact first transaction, while all rest transaction will fail with below error message showing in UI. 

    pastedimage1583155495097v1.png

  • junior AX Profile Picture
    1,552 on at

    but the custTable has accountNum as a unique index so when 6 users click it at the same time, that means all the 6 users will try to take the same account Number. So isn't the logical output to be that one user will insert successfully and the others will get that the record already exists?

    and the answer to my question when we get such errors, how can we handle them in code so that they won't appear to the user. I mean the code should make the others wait then proceed, isn't that doable?

    One more thing, i tried to reproduce the issue but i got no errors: Am i not locking the same record in the code below?

    try

    {

     ttsbegin;

     while select forupdate custtable1 where custtable1.accountnum = "1"

     {

        select forupdate custtable2 where custtable2.accountNum ="1"

        custtable2.update();

        custtable1.update();

     }

     ttscommit;

    }

    catch

    {

    }

    plus what is the difference between update conflicts and deadlock?

  • Suggested answer
    nmaenpaa Profile Picture
    101,172 Moderator on at

    Well, we don't know how you create the account numbers for the customers. If you take it from the number sequence, each 6 users would get a different number.

    Remember that the more information you share with us, the better help you will get since we don't know anything about your solution except what you choose to tell us.

    Update conflict means that two users tried to change the same record. This is triggered when the second update notices that RecVersion was changed. It's detected by Dynamics.

    Deadlock happens on database level, when two update operations are waiting for locks from each other to get released. 

  • nmaenpaa Profile Picture
    101,172 Moderator on at

    And in your code above, you didn't make any changes to the record so there's no conflict.

  • Suggested answer
    Sukrut Parab Profile Picture
    71,739 Moderator on at

    You should read about OCC  and blog below to understand update conflict and deadlocks.

    docs.microsoft.com/.../optimistic-concurrency-control

    www.dynamicsaxtraining.com/.../what-is-lock-deadlock-in-dynamics-ax

  • junior AX Profile Picture
    1,552 on at

    I forgot to update the field. Below is the code. but still i get no errors. I think based on your definition this should be an update conflict because i'm trying to update the same record. but this should also be a deadlock because i'm locking the record and i'm trying to lock it again with the second select for update so the second select for update should wait for the first one? am i right?  In my case i get no errors.

    try
    
    {
    
     ttsbegin;
    
     while select forupdate custtable1 where custtable1.accountnum = "1"
    
     {
        custtable1.CustGroup = "1";
    
        select forupdate custtable2 where custtable2.accountNum ="1"
        custtable2.CustGroup = 3;
    
        custtable2.update();
    
        custtable1.update();
    
     }
    
     ttscommit;
    
    }
    
    catch
    
    {
    
    }

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

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

#1
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 608

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 591 Super User 2026 Season 1

#3
CP04-islander Profile Picture

CP04-islander 430

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans