web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Filtering Subgrid using JavaScript and FetchXML

(0) ShareShare
ReportReport
Posted on by

Hi All,

I am trying to filter a subgrid based on a lookup field in the entity where the subgrid is located. 

I have the following code (below), but consistently keep getting the error "TypeError: Cannot read property 'SetParameter' of undefined"

After going through a lot of forums and blogs I have tried a number of variations such as using "window.parent.document.getElementById(etc..." 

However, I have read a lot of suggestions that SetParameter() is no longer supported with newer versions of the CRM - and this is why I am getting the error.

Does anyone know if this true, and if so any alternative I can try?

Thanks!! 

function filterSubGrid() {

  // retrieve the lookup field id
  var lookup = Xrm.Page.getAttribute("new_discipline").getValue();
  var entityid = lookup[0].id.slice(1, -1);
  var entityname = lookup[0].name;
  var entitytype = lookup[0].entityType;

  // testing to console
  console.log("TESTING!! Entity ID: " + entityid);
  console.log("TESTING!! Entity Name: " + entityname);

  // get the subgrid object
  var subgrid = document.getElementById("supportOffers");
  // testing to console
  console.log("TESTING!! Sub Grid: " + subgrid);

  if (subgrid == null){
    setTimeout(function(){
      filterSubGrid();}, 2000);
    return;
  }

  // FetchXML that we want the subgrid to be filtered on including the filter with the entity id of new_discipline
  var fetchXml =
    "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" +
      "<entity name='new_supportoffer'>" +
        "<attribute name='new_supportoffertitle' />" +
        "<attribute name='new_discipline' />" +
        "<attribute name='createdon' />" +
        "<order attribute='new_supportoffertitle' descending='true' />" +
        "<filter type='and'>" +
          "<condition attribute='new_discipline' operator='eq' value='" + entityid + "'" + "/>" +
        "</filter>" +
      "</entity>" +
    "</fetch>";

      //set the fetchxml to the subgrid element
      subgrid.control.SetParameter("fetchXml", fetchXml);
      // refresh the subgrid implementing the new fetchXml
      subgrid.control.refresh();
}


*This post is locked for comments

I have the same question (0)
  • Verified answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Hello Katie,

    AFAIK there is no working solution at the moment for 8.2/9.0.

  • Aric Levin - MVP Profile Picture
    30,190 Moderator on at

    Hi Katie,

    There was a way to do it previously in CRM 2015, but this stopped working after 2015 Update 1.

    Currently there is no way of doing this with subgrids. You can only create custom views and use them within lookups.

    Hope this helps.

  • Community Member Profile Picture
    on at

    Thanks Andrew, thought this might have been the case.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans