SubGrids are a great improvement which were added in CRM 2011 that allow you to easily add a grid of related entities to a form rather than navigating from the left menu. Here is a simple example of how to refresh the parent form when an update to the subgrid has occurred.
In my example updates to the results records trigger a call out which updates the average mark on the contact record so I want to redisplay the contact form after any changes to the subgrid.
First I added the sub grid to my contact form in the usual way
I then added the following Javascript to fire when contact form loads
function ContactLoad()
{
var grid = document.getElementById("ExamResults");
grid.attachEvent("onrefresh", ReLoadContact);
}
function ReLoadContact()
{
window.location.reload(true);
}
The Javascript simply attaches an event hander to the subgrid refresh event so that the function ReloadContact get called when the sub grid refreshes. As I said this is a simple example and another way would be to do an OData call from Javascript and update the required parent form field.
function ContactLoad()
{
var grid = document.getElementById("ExamResults");
grid.attachEvent("onrefresh", ReLoadContact);
}
function ReLoadContact()
{
window.location.reload(true);
}
The Javascript simply attaches an event hander to the subgrid refresh event so that the function ReloadContact get called when the sub grid refreshes. As I said this is a simple example and another way would be to do an OData call from Javascript and update the required parent form field.



Hi,
ReplyDeleteMy subgrid is update by the plugin code.
I need to know how to refresh all form if the entites in the subgrid have been updated.
Please help.
I tried this code but it gives me a null error (There was an error with this fields's customized event. Field:window Event:onload Error:'null' is null or not an object). How do I fix that.
ReplyDeleteTrying debugging the Javascript. Check you have the correct ID of your sub grid in the GetElementById line
Delete