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)
Answered

Difference between forUpdate keyword and selectForUpdate()

(0) ShareShare
ReportReport
Posted on by

what is the difference between select forupdate tablebuffer; statement and tablebuffer.selectforupdate() in AX 2012?

*This post is locked for comments

I have the same question (0)
  • Mahmoud Hakim Profile Picture
    17,887 on at

    Hi Surendra Konatham

    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

  • Community Member Profile Picture
    on at

    Surendra,

    it all depends on your implementation.

    May be you want to fetch data from table and then put an if condition on some records if you want to update the particular record.

    e.g.

    Select * from table;
    
    if(table.RecId)
    
    {
      if(table.value == "Xyz")
      {
    
        table.selectforupdate(true);
        //perform update
      }
      else
      {
        //perform your logic
      }
    }


    Mark answer as verified if it helps.

  • Community Member Profile Picture
    on at

    Thank u

  • Verified answer
    Erling Damsgaard Profile Picture
    25 on at

    Noooooooooooooooooo 

    You have misunderstood the method, TOTALLY!

    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 do not reselect the record.

    Here is how the bestpratice 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 didnt know about how to make a find method and why:
    https://msdn.microsoft.com/en-us/library/aa879893.aspx

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

    /Erling Damsgaard

    Optimate, D365 Developer since Atlanta (code name for AX in 1997)

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

    Hi Surendra,

    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.

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