In Microsoft Dynamics 365, there may be an occasion that you need to refresh the Main view for an entity programmatically. For instance, if you are performing a custom process on a record from the view, and want the view to update automatically to reflect this as soon as the process has completed.
In this instance, as you are not on a form, there is no access to the Xrm.Page data client side functionality, which severely limits your ability to refresh data in a supported manner. The only supported way to do this currently is to force a page reload, which is not ideal if there is other contextual information on the page, or buttons that you want the user to be able to interact with, not to mention it breaks the flow of the application, which can prove to be annoying for users.
The other way to go about doing this is via direct DOM manipulation, which is of course, unsupported.
There are a couple of different ways to do this.
A similar data refresh effect can be accomplished by using some vanilla JavaScript and triggering the click event of the refresh button on the subgrid. This process can be broken down into a couple of steps:
That’s it. At this point, your custom code should refresh the view grid. I would recommend wrapping this functionality in a try/catch block in case something changes in the future, to prevent this from raising an error to the user.
You can also get the grid element by use of JavaScript, and then call the refresh method of the grid control.
Again, I would strongly suggest that if you decide to use this function, or a combination of the two, to wrap this in a try/catch block so that if anything does go wrong, an error is not presented to the user.