Introduction
In Microsoft Dynamics 365 Finance & Operations (D365FO), refreshing the form after an action (like inserting, updating, or deleting a record) is essential for keeping the UI updated with the latest data. In this blog, we’ll explore two ways to refresh the form in X++:
âś… Refreshing the entire form using taskRefresh
âś… Refreshing a specific data source using research
Let's dive into the best practices for implementing these refresh methods!
🔄 Refreshing the Entire Form
If you need to refresh the whole form, use the taskRefresh
method. This method is useful when multiple data sources are involved, and you want to reload everything.
📌 X++ Code for Full Form Refresh
🔍 How It Works
- Gets the form instance using
this.formRun()
. - Checks if
formRun
is not null (to avoid errors). - Calls
formRun.task(#taskRefresh)
to refresh the entire UI. - Displays an info message when the refresh happens.
đź’ˇ When to Use?
- After inserting or updating records that affect multiple data sources.
- When you want to ensure all changes are reflected in the UI.
🔄 Refreshing a Specific Data Source
Instead of refreshing the entire form, sometimes you just need to refresh a specific data source. This can improve performance by reloading only the required data.
📌 X++ Code for Data Source Refresh
🔍 How It Works
- Calls
research()
on the specific data source to reload data. - Does not affect other data sources in the form.
đź’ˇ When to Use?
- When only a single table is updated, and you don’t need to refresh the full form.
- To improve performance by avoiding unnecessary UI reloads.
🔄 Bonus: Ensuring Data Accuracy with reread()
If you're updating records but haven’t committed the changes to the database yet, you should use reread()
before research()
.
public void refreshDataSource()
{
Table_ds.reread(); // Reloads the latest uncommitted data
Table_ds.research(); // Refreshes the UI
}
📝 Conclusion
Refreshing forms in D365FO is crucial for ensuring a smooth user experience. Depending on your needs, you can:
âś… Use taskRefresh
to reload the entire form.
âś… Use research
to refresh a single data source.
âś… Combine reread()
+ research()
to handle unsaved changes.
By implementing these best practices, you’ll improve form responsiveness and data accuracy in your D365FO applications! 🚀
Comments
Post a Comment