Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

what is the difference between "for update' and "selectforupdate" ?

(0) ShareShare
ReportReport
Posted on by 2

Hi all

Can you please let me know what is the difference between "for update' and "selectforupdate" ?.

Please give me more shed on this.

Thanks!

*This post is locked for comments

  • Martin Dráb Profile Picture
    Martin Dráb 231,409 Most Valuable Professional on at
    RE: what is the difference between "for update' and "selectforupdate" ?

    No, you still didn't get that selectForUpdate() says whether the record should be selected from database for update, therefore it must be called before the select. This makes a hige difference in case of pessimistic locking. And if you want to set a value, you must provide one (e.g. use selectForUpdate(true) instead of just selectForUpdate()).

    You also didn't get my point about find(). find() methods have a parameter which is passed to selectForUpdate() before select, therefore you should call something like Table1::find("id1", true) if you want to select a record for update. Calling selectForUpdate() after that has absolutely no effect whatsoever.

  • Suggested answer
    Sukrut Parab Profile Picture
    Sukrut Parab 71,680 Moderator on at
    RE: what is the difference between "for update' and "selectforupdate" ?

    There is no specific criteria, usually when we select buffer using find method then we do

    table. selectForupdate();

    e.g.

    table1 = Table1::find();

    table1.selectforupdate();

    if you wrote simple select statement then you can do it as combined statement

    select forupdate table1

    look at this similar thread

    https://community.dynamics.com/ax/f/33/t/264453

  • @rp@n Profile Picture
    @rp@n 2 on at
    RE: what is the difference between "for update' and "selectforupdate" ?

    Thanks Martin

  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 231,409 Most Valuable Professional on at
    RE: what is the difference between "for update' and "selectforupdate" ?

    You can mark a buffer for update and then do a select:

    myTable.selectForUpdate(true);
    select myTable;

    Or you can combine the same thing into a single statement:

    select forUpdate myTable;

    We usually use the shorter variant, but sometimes you need something else, e.g. if you want to select for update conditionally:

    myTable.selectForUpdate(_update);
    select myTable;

    You can see the last case in find() methods, for instance.

  • @rp@n Profile Picture
    @rp@n 2 on at
    RE: what is the difference between "for update' and "selectforupdate" ?

    No Sukrut

    I am not telling that I want to use  both statement in one statement.

    I know both are different statements and we can use it only 1at a time.

    My question is when to select which statement ? Is there any specific criteria?

    Please give me more shed on this.

    Thanks!

  • Sukrut Parab Profile Picture
    Sukrut Parab 71,680 Moderator on at
    RE: what is the difference between "for update' and "selectforupdate" ?

    If you specify while select forupdate then you don't have to specify again in the loop like table.selectForupdate() as you are already selecting it forupdate in a while statement.

  • @rp@n Profile Picture
    @rp@n 2 on at
    RE: what is the difference between "for update' and "selectforupdate" ?

    Thanks Hossein

    You mentioned the difference between update() and do update () but I wants to know  the exact difference between

    while select forupdate <Table name>

    where condition...

    {

         <Table.update() OR Table.doUpdate();>

    }

    And

    table.selectforupdate(true);

    Is't both are same statement?

    Please give me more shed on this.

    Thanks!

  • Suggested answer
    Hossein.K Profile Picture
    Hossein.K 6,646 on at
    RE: what is the difference between "for update' and "selectforupdate" ?

    Hi,

    In update() values stored in buffer then update the record with reference to RecID & doupdate() can directly update the record with out cheking the condisions and all. 

    if we want to select particular record with some conditons....then we use update() method.but In some situation we didn't need to chek the condition,in that situation we use DoUpdate().

    In fact,

    The doUpdate table method updates the current record with the contents of the buffer. This method also updates the appropriate system fields.

    The doUpdate method should be used when the update method on the table is to be bypassed. Suppose you have overridden the update method of the table but sometime there is a situation when you don't want the code written in the overridden update method to be executed and at the same time want any selected record of that table to be updated. In such situation you should call the table.doupdate() method instead of table.update() method.

  • @rp@n Profile Picture
    @rp@n 2 on at
    RE: what is the difference between "for update' and "selectforupdate" ?

    Thanks Hossein

    My question is

    1. ttsbegin;

    while select forupdate <Table name>

    where condition...

    {

          <Table.update() OR Table.doUpdate();>

    }

    ttscommit;

    2. table.selectforupdate(true)

    Both are same ?

    please give me more shed on this.

    Thanks!

  • Suggested answer
    Hossein.K Profile Picture
    Hossein.K 6,646 on at
    RE: what is the difference between "for update' and "selectforupdate" ?

    Hi,

    You can use SQL statements, either interactively or within source code, to access and retrieve data that is stored in the database. You use the following statements for data manipulation:

    select – Select the data to modify.

    insert – Add one or more new records to a table.

    update – Modify data in existing table records.

    delete – Remove existing records from a table.

    Before any data can be changed, you must use a select statement to select the data to update. The select forUpdate command selects records for update only. The insert, update, and delete statements perform operations on one record at a time. The array insert, insert_recordset, RecordInsertList, and update_recordset statements perform operations on multiple records at the same time.

    Regards Hossein

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,409 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans