Filter Subgrid 2015 Online Update 1 - SetParameter is null RRS feed

  • Question

  • Hi all,

    I have my code as advised by this article:


    I use window.parent.document.getElementById to get the subgrid reference and it ALWAYS returns NULL even after the setting timeout.

    I then tried Xrm.Page.getControl("subgridname").getGrid() to get the subgrid reference which works but then when I use control.SetParameter it returns "unable to get property 'SetParameter' of undefined or null reference"

    I do realise this is unsupported but it seems like this is the only way to do it, has anyone got this to work?

    My code is:

    function GetSubgrid() {
        var relatedOpportunitiesGrid = window.parent.document.getElementById("Pursuit_Team");
        if (relatedOpportunitiesGrid == null) {
            setTimeout('GetSubGrid()', 500);
        var fetchXml = "<fetch>Fetxml goes here</fetch>";
        if (relatedOpportunitiesGrid.control != null) {
            relatedOpportunitiesGrid.control.SetParameter("fetchXml", fetchXml); //set the fetch xml to the sub grid   
            relatedOpportunitiesGrid.control.refresh(); //refresh the sub grid using the new fetch xml
        } else {
            setTimeout('GetSubGrid()', 500);

    Friday, February 12, 2016 6:03 AM

All replies

  • Hi,

    Before CRM Online 2015 Update 1 the only unique method for the subgrid control was refresh. When you know the name of the subgrid control you can access it using the following code, for example, to access the CONTACTS subgrid in the default account form.

    You can use below supported way to get the grid object.

    var contactsSubgrid = Xrm.Page.getControl("Pursuit_Team");

    Please check  this blog



    Hope this helps.

    var contactsSubgrid = Xrm.Page.getControl("Contacts");

    If you find this post helpful then please "Vote as Helpful" and "Mark As Answer". Thanks and Regards, Mohammad Yusuf Ansari http://microxrm.blogspot.in

    Friday, February 12, 2016 10:46 AM
  • Hi Stanley,

    Below is the working code which I checked in  MS crm 2016 online.Modify your code similarly.

    function AccountOnLoad() {
    function filterContractsGrid() {
        //get the subgrid 
        var objSubGrid = window.parent.document.getElementById("subgrid_opportunity");
        //CRM loads subgrid after form is loaded.. so when we are adding script on form load.. need to wait until sub grid is loaded. 
        // that's why we are adding a delay..
        var isGridLoaded = null;
        try {isGridLoaded = objSubGrid.control.getEntityName();}
            setTimeout(filterContractsGrid, 2000);
        if (isGridLoaded != null) 
    		var FetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>"+
      "<entity name='account'>"+
        "<attribute name='name' />"+
        "<attribute name='address1_city' />"+
        "<attribute name='primarycontactid' />"+
        "<attribute name='telephone1' />"+
        "<attribute name='accountid' />"+
        "<order attribute='name' descending='false' />"+
        "<filter type='and'>"+
          "<condition attribute='statecode' operator='eq' value='0' />"+
          "<condition attribute='name' operator='like' value='%ski%' />"+
        "<link-entity name='contact' from='contactid' to='primarycontactid' visible='false' link-type='outer' alias='accountprimarycontactidcontactcontactid'>"+
          "<attribute name='emailaddress1' />"+
    // Layout of subgrid.
            var LayoutXml = "<grid name='resultset' object='1' jump='title' select='1' preview='1' icon='1'>" +
                                " <row name='result' id='mmp_name'>" +
                                        "<cell name='name' width='300' />" +
                                        "<cell name='address1_city' width='200' />" +
                                        "<cell name='telephone1' width='100' />" +
                                    "</row>" +
     //apply layout and filtered fetchXML
            objSubGrid.control.SetParameter("layoutXml", LayoutXml);
            objSubGrid.control.SetParameter("fetchXml", FetchXml);
            //Refresh grid to show filtered records only. 

    Hope this helps,

    If you find this post helpful then please "Vote as Helpful" and "Mark As Answer". Thanks and Regards, Mohammad Yusuf Ansari http://microxrm.blogspot.in

    Friday, February 12, 2016 2:30 PM
  • Thanks Mohammad, I will test and get back you, appreciate you testing this out.
    Monday, February 15, 2016 1:57 AM