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)

Tablebuffer selectforupdate

(1) ShareShare
ReportReport
Posted on by 3,542

I have always assumed the following statements are similar and for all practical purposes identical

1)

Tablebuffer tbl;

tbl.selectForUpdate(_forUpdate);

select tbl where {some condition}

2)

Tablebuffer tbl;

select forUpdate tbl where {some condition}

I came across the CompanyImage table find method:

VirtualBox_5F00_Mah-Man-VM_5F00_04_5F00_05_5F00_2018_5F00_08_5F00_57_5F00_23.png

So it seems there must be a difference as the author of this method (all hail Microsoft) used both.

Thanks for reading

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    István Orosz Profile Picture
    2,137 on at

    Hi,

    The selectForUpdate() sets a property on the tablebuffer, when the select is performed next time the record is locked. When select forUpdate selects records for update only.

    Pleas see this article: Difference between forUpdate keyword and selectForUpdate.

    Kind regards,

    István

  • Pete Alberts Profile Picture
    3,542 on at

    Thank you very much

    So in summary:

    selectForUpdate: selects for update AND locks record

    forupdate: only selects for update

    Correct?

    This still does not explain why the find method in CompanyImage uses both.

    (I read the article you referenced before I posted this.)

    This also brings me to a related question: Why is the source code for these methods not available? It would make my life much easier if I could just "Go To Definition".

  • Suggested answer
    Mea_ Profile Picture
    60,284 on at

    Hi Pete Alberts,

    selectForUpdate and forupdate work identically. The main difference between two - is the usage. You can pass a value to selectForUpdate() method to set it before actual select and you cannot put "if" statement or any condition to disable or enable "forupdate". So you use selectForUpdate() when you need to enable it base on a condition and "forupdate" when record is always selected for update.

  • Pete Alberts Profile Picture
    3,542 on at

    Thanks man.

    I got that. :)

    Please look at the CompanyImage example I attached in the OP. As/if the two are (basically) identical, it means the Microsoft developer who wrote that find method didn't know what he was doing. Which is very unlikely, but seems to be the inevitable answer?

  • Verified answer
    Mea_ Profile Picture
    60,284 on at

    Looking at index hint in the select statement (that is deprecated since 2012) I would say its very old legacy code that may be created before MS. Also please remember that standard code has tons of BP violations, so it's not always ideal. It works but does select for update 2 times that is not a big deal.

  • István Orosz Profile Picture
    2,137 on at

    ievgen is right, the logic is the same in AX2009 also:

    CompanyImage_5F00_Find.JPG

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