🎯 Objective
In many scenarios, record locking at the UI level is essential to prevent multiple users from editing the same data simultaneously. In this blog, we’ll walk through how to restrict users from opening a Sales Order form if another user already has it open, and throw a relevant error message like:
"The same Sales order is already opened by another user."
🏗️ Step-by-Step Implementation
✅ Step 1: Add a New Field to SalesTable
-
Navigate to AOT → Data Dictionary → Tables → SalesTable
-
Add a new field named
UserLockId
-
Type:
String
-
Label: User Lock ID
-
Purpose: Store the ID of the user who has opened the Sales Order
-
✅ Step 2: Override init()
Method on SalesTable Form
Update the SalesTable Form → Methods → init()
as follows:
✅ Step 3: Release the Lock in close()
Method
Also, override the close()
method in the same form to release the lock when the user closes the form:
💡 Key Considerations
-
This solution assumes all users are opening Sales Orders from a standard menu item or list page and not through batch processes or APIs.
-
You can expand this logic using flags or timestamps for better control (e.g., lock expiry).
-
Don’t forget to refresh the SalesTable cache if you're facing visibility issues on the updated field.
📌 Use Case Scenarios
-
Preventing duplicate data entry on transactional forms
-
Ensuring single-user access to critical financial records
-
Custom user-specific form locks in approval workflows
✅ Summary
This approach provides a lightweight form-level record lock in D365FO using a custom field and simple logic in the init()
and close()
methods. It’s particularly useful for high-importance forms where data integrity and editing control are crucial.
0 Comments