Search code examples
dynamics-crmcrmdynamics-crm-online

SetParameter("fetchXml", FetchXml) doesn't support in crm 2016 online


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


Solution

  • 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:

    var myView = {
        entityType: 1039, // SavedQuery
        id:"{3A282DA1-5D90-E011-95AE-00155D9CFA02}", 
        name: "My Custom View"
    }
    
    //Set the view using ContactsIFollow
    Xrm.Page.getControl("Contacts").getViewSelector().setCurrentView(myView);