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, ...
Suggested Answer

Update recordset getting stuck in D365 F&O

(0) ShareShare
ReportReport
Posted on by 758

Hi Everyone,

I am running one batch job which has following code into it,

 public void processOperation(MyContract _contract)
 {
    #OCCRetryCount
        try
        {
            ttsbegin;
            // multiple methods being called from here
            ttscommit;
        }
        catch (Exception::Deadlock)
        {
            retry;
        }
        catch (Exception::UpdateConflict)
        {
            if (appl.ttsLevel() == 0)
            {
                if (xSession::currentRetryCount() >= #RetryNum)
                {
                    throw Exception::UpdateConflictNotRecovered;
                }
                else
                {
                    retry;
                }
            }
            else
            {
                throw Exception::UpdateConflict;
            }
        }

 }

One of the method being called from try..catch loop is as below,

while select myTable
        where myTable.DocId == _docId
{
    boolean isRecordMatched = //returning boolean from one custome method
    if(isRecordMatched)
    {
        myTable.selectForUpdate(true);
        myTable.IsMarked = NoYes::Yes;
        myTable.CustTransRefRecId = custTrans.RecId;
        myTable.CustTransOpenRefRecId = custTransOpen.RecId;
        myTable.update();
    }
}


In above code MyTable is a custom line table & below are it's properties,


1. Cache lookup :NotInTTS

2. Table group: Worksheet Line

3. OCC enabled : Yes

and it has one index with DocId & Line number..

The above batch job runs for 2-3 hours approx. I have only included TTSBEGIN & TTSCOMMIT only in try..catch loop

However, I have one more functionality, where I click on Custom button and update the data from same MyTable using updateRecordset query but for different DocId.

And it's getting stuck over there. Even if I am trying to update data from same table for different records in SQL server directly, the query gets stuck in executing mode.

Whenever the batch job gets completed, everything works fine. updateRecordset does not get stuck & even I am able to update the data through SQL as well.

What could be the reason behind it? Why it's locking my complete table? How should I modify my code to allow parallel execution of both updates for different records?

I have the same question (0)
  • Suggested answer
    Rhushikesh R Profile Picture
    758 on at

    Well I have come across below blog,

    Blocking in D365FO(and why you shouldn't always follow MS recommendations) | Denis Trunin's X++ Programming Blog

    pastedimage1639567128480v1.png

    And if I am using while select forupdate in another query, which is being called from Custom button click, it is not blocking/locking my custom table.

  • André Arnaud de Calavon Profile Picture
    301,075 Super User 2025 Season 2 on at

    Hi Rhushikesh,

    How many records do you have in this table and how many records are having the _docId value? Do you expect e.g. 10-50 records or thousands?

    If you expect a smaller number of records, then check if the _docId has an actual value. Have a look at my blog which also describes how to mitigate performance issues to first evaluate the parameter value: Slow or fast? Performance considerations for the while select statement - Dynamicspedia

    Besides, what is the actual logic in the method returning the value for your isRecordMatched variable?

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

#2
André Arnaud de Calavon Profile Picture

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

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 278 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans