Add or Remove Events for Sub-grids in Dynamics 365

Zoe Sands, 23 January 2019

In Dynamics 365, you can add or remove onload events from a sub-grid by referencing functions by name. The two examples below show how this is done.

Xrm.Page.getControl("mag_mygrid").addOnLoad(myMethod);
Xrm.Page.getControl("mag_mygrid").removeOnLoad(myMethod)


image


Because the addOnLoad and removeOnLoad functions only accept the event function name as a parameter, you cannot pass additional parameters to your function using this approach.

A workaround is to use anonymous functions instead.

Xrm.Page.getControl("mag_mygrid").addOnLoad(function(){ myMethod (parameter} });

The downside to this is that you cannot remove the anonymous function above as it does not have a function name.