I'm trying to set the values in a subgrid in 2013 in the onload of a form.
I can't get the subgrid though, I keep getting an error saying 'unable to get property X of undefined or null reference'. I've tried a few different ways of doing this.
Namely:
var subgrid = document.getElementById("Quote"); var subgrid = Xrm.Page.getControl('Quote'); var subgrid = Xrm.Page.ui.controls.get('Quote') var subgrid = Xrm.Page.getControl(43); var subgrid = Xrm.Page.ui.controls.get('Quote')._control;
I got the 43 value when I used F12 to get the developer tools and had a look at the code.
This is my code in its entirety:
function LoadQuoteSummaryGrid() { //var subgrid = document.getElementById("Quote"); //var subgrid = Xrm.Page.getControl('Quote'); //var subgrid = Xrm.Page.ui.controls.get('Quote') //var subgrid = Xrm.Page.getControl(43); var grid = Xrm.Page.ui.controls.get('Quote')._control; if (grid.get_innerControl() == null) { setTimeout(LoadQuoteSummaryGrid, 1000); return; } else if (grid.get_innerControl()._element.innerText.search("Loading") != -1) { setTimeout(LoadQuoteSummaryGrid, 1000); return; } //if (grid == null) //{ //alert("Subgrid is null"); //The subgrid hasn't loaded, wait 1 second and then try again //setTimeout('LoadQuoteSummaryGrid()', 1000); //return; //} var fetchXml = "<fetch>"+ " <entity name='email'>"+ " <attribute name='from' />"+ " <attribute name='to' />"+ " <attribute name='subject' />"+ " <attribute name='modifiedon' />"+ " <attribute name='activityid' />"+ " <order attribute='modifiedon' descending='true' />"+ " <link-entity name='activityparty' from='activityid' to='activityid' alias='aa'>"+ " <filter type='and'>"+ filter+ " </filter>"+ " </link-entity>"+ " </entity>"+ " </fetch>"; //alert("fetchXml: " + fetchXml); //Inject the new fetchXml grid.control.setParameter("fetchXml", fetchXml); //Force the subgrid to refresh grid.control.refresh(); }
I'm leaving in the commented out lines, so you can see what I've tried so far.
Thanks.