I have this code:
function FilterCasesSubgrid() {
//var CasesSubgrid = Xrm.Page.getControl("contact").getGrid();
var CasesSubgrid = window.parent.document.getElementById("contact");
if(CasesSubgrid==null){
setTimeout(function () { FilterCasesSubgrid(); }, 2000); //if the grid hasn’t loaded run this again when it has
return;
}
var fetchXml ="<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>"+
"<entity name='contact'>"+
"<attribute name='fullname' />"+
"<filter type='and'>"+
"<condition attribute='fullname' operator='eq' value='s%' />"+
"</filter>"+
"</entity>"+
"</fetch>";
//Here i set the fetchxml directly to subgrid
CasesSubgrid.control.SetParameter("fetchXml", fetchXml); //set the fetch xml to the sub grid
CasesSubgrid.control.Refresh(); //refresh the sub grid using the new fetch xml
}
ERROR :
TypeError: Cannot read property 'SetParameter' of undefined at FilterCasesSubgrid
You'll need to wait for the element AND the control property (CasesSubgrid.control).
This was already answered here
This code isnt supported so you shouldnt expect it to work. Using any function which directly accesses the DOM (i.e;
window.parent.document.getElementById
) or uses function not defined within the MSDN SDK is unsupported and should be avoided.However, given that all you seem to be doing is adding a filter, there are supported methods for doing this by setting an existing FetchXML query:
Here's the solution:
So the code would look like this: