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 :
Microsoft Dynamics AX (Archived)

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

(0) ShareShare
ReportReport
Posted on by 30

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

I have the same question (0)
  • Suggested answer
    guk1964 Profile Picture
    10,888 on at

    I suggest read this last entry on this  by the 'man; himself"

    https://community.dynamics.com/ax/f/33/t/264453  I have reproduced it here:

    The selectForUpdate(..) method is used to set a property on the buffer, so that next time a select is performed the record is locked (if selectForUpdate(true) is used). The method does not reselect the record.

    Here is how the best pratice find method should be created on a table:

    static InventTable find(ItemIditemId, boolean update = false)
    {
        InventTable inventTable;
        inventTable.selectForUpdate(update);
        if (itemId)
        {
            select firstonly inventTable
                index hint ItemIdx
                where inventTable.itemId == itemId;
        }
        return inventTable;
    }
    

    Please see the documentation for AX/Dynamics 365:

    https://docs.microsoft.com/en-us/dynamics365/unified-operations/dev-itpro/dev-ref/xpp-data-query#transactional-integrity

    If you didn't know about how to make a find method and why then read:
    https://msdn.microsoft.com/en-us/library/aa879893.aspx

    https://msdn.microsoft.com/en-us/library/aa672421.aspx

    There are lot of different posts on this topic on different sites so be careful what you read.

  • Suggested answer
    Mahmoud Hakim Profile Picture
    17,887 on at

    selectForUpdate Method  return true or false

    https://msdn.microsoft.com/en-us/library/xrecord.selectforupdate.aspx 

    and select for update table buffer, selects records for update only. Depending on the underlying database, the records might be locked for other users

    docs.microsoft.com/.../xpp-data-query

  • Suggested answer
    Hossein.K Profile Picture
    6,648 on at

    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

  • @rp@n Profile Picture
    30 on at

    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
    6,648 on at

    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
    30 on at

    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!

  • Sukrut Parab Profile Picture
    71,710 Moderator on at

    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
    30 on at

    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!

  • Verified answer
    Martin Dráb Profile Picture
    237,967 Most Valuable Professional on at

    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
    30 on at

    Thanks Martin

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 > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans