Notifications
Announcements
No record found.
Hello,
I want to lock a table record.
When another trying to select that record, it wait, until I unlock the record.
How can I do that?
X++ (AX 2012).Thanks :)
*This post is locked for comments
you select it for update using the standard X++ syntax
To ensure it actually acquires a lock you need to use pessimistic concurrency
however, it's discouraged in AX, as this is a multi-user environment, and locks cause large delays for other users wanting to update data in the same table
I do:
Station 1:
...
ttsbegin;
myTable.selectForupdate();
Station 2:
myTable.selectForupdate(); // same record.
... // there is no waiting !!!
I need to do "wait" after myTable.selectForupdate for station 2.
Thanks :)
First of all, selectForUpdate() just sets the update flag for the next select statement; it doesn't make any call to database to lock anything. Your snippet doesn't show whether you execute such select statements or not.
Secondly, Ivan clearly wrote that you have to use pessimistic concurrency control, but you didn't mention anything about it. If the table should always use pessimistic concurrency, set its OccEnable property to No. If it should be for the particular selects only, use "select pessimisticLock" or set concurrencyModel() on the buffer.
OK, I will check that out.
Well,
I did select for update.
i.e:
static void splTestRec1(Args _args)
{
GeneralJournalAccountEntry generalJournalAccountEntry;
;
ttsBegin;
select forupdate generalJournalAccountEntry
where generalJournalAccountEntry.RecId == 12345;
ttsCommit; // *****
}
1. I Ran the above on one session, and the debugger command is before commit ran.
2. I Ran the above on other session, and when doing the "select" statement, I accept that there will be "waiting", and there isn't any.
How can I do lock+wait? Need a code example, please.
Where did you set pessimistic locking, as mentioned in both Ivan's and my answers? Replace forUpdate with pessimisticLock and try it again.
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.
As AI tools become more common, we’re introducing a Responsible AI Use…
We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…
These are the community rock stars!
Stay up to date on forum activity by subscribing.
Priya_K 4
Martin Dráb 4 Most Valuable Professional
Ali Zaidi 2