Attach Logic to Sub-Grid after being Loaded in CRM 2013

I did not find a script online for CRM 2013 that could help. So here it goes:

 

function subGridOnload()
{
var grid = $(‘#gridname’);  //Replace Grid name here
if (grid == null)
{
// delay one second and try again.
setTimeout(subGridOnload, 1000);
return;
}
 
if(grid[0] == undefined)
{
  // delay one second and try again.
setTimeout(subGridOnload, 1000);
return;
}
 
  if(grid[0].control == undefined)
{
  // delay one second and try again.
setTimeout(subGridOnload, 1000);
return;
}
 
  if(grid[0].control == null)
{
  // delay one second and try again.
setTimeout(subGridOnload, 1000);
return;
}
 
if (grid[0].control.get_totalRecordCount() == -1)
{
   // delay one second and try again.
setTimeout(subGridOnload, 1000);
return;
}

//Logic goes here

}

Note: This is unsupported and might break in future!

Hope it helps!

Leave a comment