Skip to content

CRM 2011 Filtering Records in The Sub grid with Javascript

November 27, 2012

If you want to filter sub grid record based on a condition, this post will help you as an example..

function FilterSubgrid() {
var filterId=Xrm.Page.data.entity.getId();
var yoursubgridnameObject= document.getElementById(“yoursubgridname”);
if (yoursubgridnameObject== null || yoursubgridnameObject.readyState != “complete”) {
setTimeout(‘FilterSubgrid()’, 1000);
return;
}
if(filterId==null) return;
var fetchXml = “<fetch version=’1.0′ output-format=’xml-platform’ mapping=’logical’ distinct=’false’>”;
fetchXml += “<entity name=’employee’>”;
fetchXml += “<attribute name=’employee_name’/>”;
fetchXml += “<attribute name=’employee_lastname’/>”;
fetchXml += “<attribute name=’employee_gender’/>”;
fetchXml += “<attribute name=’employee_birthdate’/>”;
fetchXml += “<order attribute=’employee_name’ descending=’false’ />”;
fetchXml += “<filter type=’and’>”;
fetchXml += “<condition attribute=’statecode’ operator=’eq’ value=’0′ />”;
fetchXml += “<condition attribute=’employee_workid’ operator=’ne’ uitype=’employee_workid‘ value='”+filterId+”‘/>”;
fetchXml += “</filter>”;
fetchXml += “</entity>”;
fetchXml += “</fetch>”;
yoursubgridnameObject.control.setParameter(“fetchXml”, fetchXml);
yoursubgridnameObject.control.refresh();
}

From → CRM 2011

Leave a Comment

Leave a comment