Wednesday, June 08, 2011

CRM 2011 - How to refresh a form after subgrid changes

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.





8 comments:

  1. Hi,

    My 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.

    ReplyDelete
  2. 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.

    ReplyDelete
    Replies
    1. Trying debugging the Javascript. Check you have the correct ID of your sub grid in the GetElementById line

      Delete
    2. GetElementById line this gives null now how can i fix that.

      Delete
    3. See my previous reply

      Delete
  3. In my example updates to nhl jerseys shop the results records trigger a call out which updates the average mark on the contact record so I want to nike jersey redisplay the contact form after any changes to the subgrid.

    ReplyDelete
  4. Awesome Article.

    And Joe is there anyway that we can refresh the form, After note is being added to the form.

    ReplyDelete
  5. Hello,

    thanks for your tutorial. I have one Problem: I would like to attach the "OnRecordInserted" "OnRecordUpdated", "OnRecordDeleted" event on the subgrid.

    The main problem is, that if I attach my function to the "onrefresh" event, sometimes the event already gets triggered when my main form is loaded for the first time, so when I insert a new record into my subgrid a page reload will occur and it ends up in an endless loop.

    When I analyze the subgrid object within the IE9 Debugger, I can see a lot of other events, but I can't attach my function to it:

    http://www.inqubit.de/Temp/subgrid_events.png

    Would like to hear what you think about that attaching other events then onrefresh.

    ReplyDelete