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

Select forupdate in X++ only update first record of the table

(1) ShareShare
ReportReport
Posted on by
Hello,
I have a table and I used select forupdate but it only updates the first record using X++.
How can I update all the records that are under the condition of the query.
I have the same question (0)
  • Anton Venter Profile Picture
    20,301 Super User 2025 Season 2 on at
    Select forupdate in X++ only update first record of the table
    Hello,
     
    You probably have an incorrect syntax or doing a "select first" in your statement. The easiest way is to do a "while select forUpdate" statement, change the data and call the update method. This is a slow method. Use update_recordset for faster set based operations.
     
    Please share your code so that we can see and help you. Remember to format your code using the insert code snippet button :-)
  • Roy Saliba Profile Picture
    on at
    Select forupdate in X++ only update first record of the table
    I used while loop thank you!
  • Waed Ayyad Profile Picture
    8,961 Super User 2025 Season 2 on at
    Select forupdate in X++ only update first record of the table
    Hi,
     
    Can you share your code? Also, it is better to use  update_recordset  method.
    Did you add ttsBegin; and ttsCommit;?
     
    Thanks
    Waed Ayyad
    If this helped, please mark it as "Verified" for others facing the same issue
     
  • Anton Venter Profile Picture
    20,301 Super User 2025 Season 2 on at
    Select forupdate in X++ only update first record of the table
    See the update_recordset example below from the article, also see link below. This is a much faster update method if updating a lot of data compare to a while select forUpdate statement. The article shows important information about updates. Do mind sharing your code?
     
    CustTable custTable;
    ttsBegin;
    update_recordset custTable
        setting CreditMax = custTable.CreditMax + 1000
        where custTable.CreditMax > 0;
    ttsCommit;
     
    Update data
  • Layan Jwei Profile Picture
    8,049 Super User 2025 Season 2 on at
    Select forupdate in X++ only update first record of the table
    Hi,
     
    Select for update will only update one record, even if more than one record matches this condition.
    So if u do this:
     
    CustTable custTable;
    ttsBegin;
        select forUpdate custTable
            where custTable.CustGroup == '2';
        custTable.Field1 = 1;
        custTable.update();
    ttsCommit;
     
    And let's say you have two customers that belong to this custGroup, then only one customer will be updated.
     
    If you want all customers with this custGroup to be updated, then you have two options:
     
    1. While loop
    CustTable custTable;
    ttsBegin;
        While select forUpdate custTable
            where custTable.CustGroup == '2'
        {
            custTable.Field1 = 1;
            custTable.update();
        }
    ttsCommit;
     
    2. update_recordset
    CustTable custTable;
    ttsBegin;
    update_recordset custTable 
        setting Field1 = 1
        where custTable.CustGroup = '2'
    ttsCommit;
     
    update_recordset is better for performance, but if the update method of the table is overridden, then update_recorset will work as if it was while loop. I mean the performance won't be any better.
     
    Thanks,
    Layan Jweihan 
    Please mark this answer as "Verified" if it solved your issue. In order to help others who will face a similar issue in the future.
  • Waed Ayyad Profile Picture
    8,961 Super User 2025 Season 2 on at
    Select forupdate in X++ only update first record of the table
    Hi,

    Is your issue resolved?  If yes, mark the answers that helped you as verified.

    Thanks
    Waed Ayyad

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

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

#1
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 2,028

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 579 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans