Crm 2011/2013 Filtering SubGrid

You can filter your subgrid using the code below.
function FilterSubgrid() {

 var Subgrid = document.getElementById("yoursubgridid");
 if (Subgrid== null) {
 setTimeout(function () { FilterSubgrid(); }, 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='entityname'>"
 +"<attribute name='attributename1' />"
 +"<attribute name='attributename2'/>"
 +"<order attribute='orderattribute' descending='false' />"
 +"<filter type='filtertype'>"
 +"<condition attribute='conditionattributename' operator='operator' />"
 +"</filter>"
+"</entity>"
+ "</fetch>";
Subgrid.control.SetParameter("fetchXml", fetchXml); //set the fetch xml to the sub grid  

Subgrid.control.Refresh(); //refresh the sub grid using the new fetch xml
}

Leave a comment