CRM 2011 Update/ Custom Subgrid View/ FetchXML Subgrid


Scenario: 

I need to filter the subgrid to act as view.
Decided to create a custom subgrid view to filter based on all the records in the subgrid.
This is what i code for javascript and put it on onload form function.

Code:


function updateSubGrid() {

    var relatedProducts = document.getElementById("SubgridProjects");
    var lookupfield = new Array;
    lookupfield = Xrm.Page.getAttribute("vw_projectnoid").getValue();

    if (lookupfield != null) { var lookupid = lookupfield[0].id; }
    else { return; }

    if (relatedProducts == null || relatedProducts.readyState != "complete") { setTimeout('updateSubGrid()', 2000); return; }

    var fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>";
    fetchXml += "<entity name='vw_project'>";
    fetchXml += "<attribute name='vw_projectid' />";
    fetchXml += "<attribute name='vw_projectno' />";
    fetchXml += "<attribute name='vw_titlestatus' />";
    fetchXml += "<attribute name='vw_landtenure' />";
    fetchXml += "<order attribute='vw_projectno' descending='false' />";
    fetchXml += "<filter type='and'>";
    fetchXml += "<condition attribute='vw_projectid' operator='eq' value='" + lookupid + "' />";
    fetchXml += "</filter>";
    fetchXml += "</entity>";
    fetchXml += "</fetch>";

    relatedProducts.control.setParameter("fetchXml", fetchXml);
    relatedProducts.control.refresh();
    document.getElementById("SubgridProjects_span").disabled = true; //Disable the subgrid
}   

As u can c there no layout xml. Most of the custom view use fetch xml.  U can download ur fetch xml from advanced find.

0 comments: