{SCRIPTING TIP} Refresh CRM form asynchronously when records are changed in Sub-grid in CRM 2015 Update 1

Sometimes I have had the requirement in past to refresh CRM form when things are being added to the record sub-grid. I wasn’t able to achieve a solution in supported scripting prior to CRM 2015 Update 1.

Here is the piece of code which needs to be added to your Form on load which will take care of refreshing the form asynchronously every time anything is added to the subgrid

function onload() {

var gridOnloadFunction = function () { Xrm.Page.data.refresh(false); };