When you refresh a form data source in Dynamics AX or Dynamics 365 for Finance and Operations, the current selection is often lost — the cursor jumps back to the first record.
This can be frustrating, especially if you want the user to remain on the same record after an update or refresh.
Here’s a simple and reliable way to restore the cursor to the same record after the data source is refreshed.
π§© Scenario
Suppose we have a form displaying records from MyTable.
When we refresh the data source — for example, after updating a field or calling executeQuery() — we want the form to return to the same record the user was viewing before the refresh.
✅ Solution: Use ds.cursor()
We can achieve this using a record buffer and the cursor() method of the data source.
π§ Explanation
-
MyTable_ds.cursor()— gets the current record from the data source. -
MyTable_ds.research()orexecuteQuery()— refreshes the data source. -
MyTable_ds.cursor(myTableRec)— sets the data source cursor back to the stored record.
This ensures the same record stays selected after refresh — even if the data source re-queries the database.
Comments
Post a Comment