D365FO form datasource refresh(): when to use refresh, reread, research, and executeQuery
If a D365FO form shows stale data after an X++ update, the fix is usually not to call refresh() by itself. This article explains when to use refresh(), reread(), research(), and executeQuery(), why each one behaves differently, and the practical pattern that avoids empty grids, stale fields, and lost filters.
D365FO form datasource refresh(): when to use refresh, reread, research, and executeQuery#
If your form still shows old values after X++ updates, the problem is usually not the update itself. It is choosing the wrong datasource method afterward.
The short version is:
refresh()repaints the current records already in the form cache.reread()reloads the current record from the database.research()reruns the existing query, keeping the current query structure and user filters.executeQuery()reruns the datasource query and is the right choice when you changed the query in code.
If you only need the screen to reflect values you already updated in the database, reread() plus refresh() is usually the safest pattern. If the record set itself may have changed, use research() or executeQuery() depending on whether you changed the query. Microsoft’s datasource API descriptions line up with that behavior, and community examples repeatedly show that refresh() alone does not reread from the database. (learn.microsoft.com)
Quick rule of thumb#
Use this decision tree:
- Current record changed in the database:
reread(); refresh(); - Rows may have been added, removed, or reordered, but query shape is unchanged:
research(); - You changed ranges, joins, or other query parts in code:
executeQuery(); - You only want to repaint the grid/form from cache:
refresh();
That is the part people get wrong most often. They call refresh() after an update and expect the datasource to fetch the latest database state. It does not do that. Microsoft describes reread() as re-reading the current record from the database, while executeQuery() executes the datasource query and displays the returned records. (learn.microsoft.com)
Why refresh() alone usually disappoints#
refresh() is a UI repaint method. It does not requery the database. So if another process updated the record, or your own code updated the table buffer outside the form’s current cache, the grid can still show stale data until the datasource is reread.
This is why a lot of forum answers that say “just call refresh” only work in cases where the form cache already contains the right data. As soon as the underlying record changed, refresh() only redraws stale cache. Community discussions around form refresh behavior keep coming back to this exact distinction. (community.dynamics.com)
What each method actually does#
refresh()#
Use refresh() when the datasource cache is already correct and you just need the form to repaint. It does not query the database again. That makes it cheap, but also limited. (learn.microsoft.com)
Typical use cases:
- A display value changed in the current cache
- You toggled control state and want the grid to repaint
- You already called
reread()and just need the UI to reflect it
reread()#
Use reread() when the current record changed in the database and you want the form buffer to pick up the latest values. Microsoft describes it as re-reading the current record from the database. (learn.microsoft.com)
Typical use cases:
- Your code updated the same record with a table buffer or helper class
- A separate process committed a change to the record currently displayed
- You want the form buffer to reflect the latest values before repainting
research()#
Use research() when the record set itself may have changed, but you want to keep the existing datasource query structure and user filtering. Community examples and Microsoft employee responses consistently describe it as rerunning the existing datasource query rather than just repainting the cache. (community.dynamics.com)
Typical use cases:
- New rows were inserted and should now appear
- Some rows were deleted and should disappear
- Existing rows changed and the grid should reflect the new result set
- You do not need to rebuild the query in code
executeQuery()#
Use executeQuery() when you changed the datasource query in code and want that modified query to run. Microsoft’s API reference says this method executes the datasource query and displays the retrieved records. (learn.microsoft.com)
Typical use cases:
- You added or removed ranges in
executeQuery()override code - You changed joins, links, or query datasource settings
- You want the datasource to rerun after query-building logic changes
One important practical detail: executeQuery() is the method that most directly maps to a full query rerun, so if you modified the query in code, research() is often the wrong tool. That distinction is also why some community posts warn that executeQuery() can reset query state differently than research(). (community.dynamics.com)
The recommended pattern after updating a record in X++#
If you update data outside the current form datasource, the safe default is:
MyTable tableBuffer;
select firstOnly forUpdate tableBuffer
where tableBuffer.RecId == _recId;
if (tableBuffer)
{
ttsBegin;
tableBuffer.SomeField = _newValue;
tableBuffer.update();
ttsCommit;
}
// If you are on the form and want the current record refreshed:
MyTable_ds.reread();
MyTable_ds.refresh();Why this works:
update()commits the change to SQL.reread()reloads the current form record from SQL.refresh()repaints the screen using the now-current datasource cache.
That pattern is much more reliable than refresh() alone because it addresses both the buffer and the UI. It also matches the Microsoft-documented purpose of reread() and the community guidance around form refresh behavior. (learn.microsoft.com)
If the row set changed, use research()#
If the update can affect whether rows should appear or disappear on the form, you need the datasource to rerun the query, not just reread one record.
Example:
MyTable_ds.research();
MyTable_ds.refresh();Use this when:
- a status change makes a record no longer match the filter
- a newly created row should show up
- a deleted row should disappear
If you know the query was not changed in code, research() is usually the more user-friendly choice because it keeps the existing query logic intact while reapplying it. (community.dynamics.com)
If you changed the query, use executeQuery()#
If your code altered ranges or other query parts, research() is not enough.
Example:
QueryBuildDataSource qbds = MyTable_ds.queryBuildDataSource();
qbds.addRange(fieldNum(MyTable, Status)).value(queryValue(MyStatus::Open));
MyTable_ds.executeQuery();In this case, executeQuery() is the correct method because you changed the query definition itself. Microsoft’s datasource documentation explicitly ties executeQuery() to running the datasource query and displaying retrieved records. (learn.microsoft.com)
Common mistake: calling executeQuery() when you only needed reread()#
A lot of developers reach for executeQuery() too early.
That can be overkill when:
- only the current record changed
- you want to preserve the current form state as much as possible
- you do not need to rebuild the datasource query
In those cases, reread() plus refresh() is cleaner and less disruptive. Community guidance around preserving filters also points out that research() and executeQuery() are not interchangeable when the form query state matters. (community.dynamics.com)
Common mistake: calling only refresh() after an update#
This is the classic bug.
You update a record, call refresh(), and the form still looks wrong.
That happens because the datasource cache was never reloaded. refresh() repaints what is already there; it does not make the datasource go back to the database. Microsoft’s reread() documentation is the clue here: reread is the method that updates the record with the latest database changes. (learn.microsoft.com)
Practical recommendation#
If you want one mental model that works in most D365FO form scenarios, use this:
- Same record, updated elsewhere:
reread(); refresh(); - Different records may now qualify:
research(); - Query logic changed in code:
executeQuery(); - Just repainting the screen:
refresh();
That is the simplest practical rule, and it avoids most stale-data bugs I see in D365FO form code.
One last thing about user filters#
If your form has active filters, that matters.
The main reason people prefer research() over a blunt executeQuery() in some scenarios is that it re-runs the existing datasource query instead of reconstructing the query from scratch. Community articles and forum replies repeatedly highlight filter preservation as the practical difference users notice. (community.dynamics.com)
So when the real requirement is “show me the latest rows, but keep the user’s current filter,” research() is often the better fit than executeQuery().
Bottom line#
If your D365FO form is stale after X++ updates, do not start by calling refresh().
Start by asking:
- Did I change the current record only?
- Did the row set change?
- Did I change the query?
Then choose the method that matches the problem:
reread()for the current recordresearch()for the existing queryexecuteQuery()for a changed queryrefresh()only to repaint the UI
Sources#
- FormDataSource.reread Method (Dynamics.AX.Application) — Microsoft Learn
- FormDataSource.executeQuery Method (Dynamics.AX.Application) — Microsoft Learn
- X++ class library - Finance & Operations | Dynamics 365 | Microsoft Learn — Microsoft Learn
- Customize through extension and overlayering - Finance & Operations | Dynamics 365 | Microsoft Learn — Microsoft Learn
- Dynamics 365 Community Forum Thread Details — Dynamics Community
- Dynamics 365 Community Blogs - Differentiate Refresh, Reread, Research and Executequery — Dynamics 365 Community
Missing something?
Suggest a topic you'd like to see covered next. The most requested topics help shape future XppForge documentation.
Sign in to suggest a topic