In brief

Two supported refresh patterns cover the most common Dynamics 365 scenarios.

  • Use the selected grid control when a command changes home-page view data.
  • Use formContext.data.refresh() when you need an asynchronous form refresh.
  • Decide explicitly whether the current form data should be saved before refresh.

In Microsoft Dynamics 365, there are many occasions when you need to refresh either a form or a view programmatically using JavaScript. The two approaches below show how to do that through supported APIs.

Refresh the home page grid

Refreshing a view programmatically is useful when a custom button changes data in the home page grid and you want the view to reflect those changes immediately.

In Ribbon Workbench, pass the CRM parameter SelectedControl to your command’s custom JavaScript action. Once processing is complete, call refresh on that control.

JavaScript · selected grid control
selectedControl.refresh();

Refresh a form asynchronously

When you are already on a form and have access to its form context, the data API can refresh the form without reloading the entire page.

JavaScript · form context
formContext.data.refresh(save).then(
  successCallback,
  errorCallback
);

Understand the parameters

The refresh method accepts a save choice and optional callbacks for success and error handling.

NameTypeRequiredDescription
saveBooleanNoSave form data before refreshing when set to true.
successCallbackFunctionNoRuns when the refresh completes successfully.
errorCallbackFunctionNoRuns if the refresh operation fails.

That is all you need for the two most common supported refresh scenarios. Keep the save choice explicit and use callbacks when the surrounding experience needs clear success or error handling.

Related resource

Discuss a CRM customisation

If your team needs a tailored CRM feature, explore Custom Development and discuss the requirement, support and maintenance involved.
Open resource