Skip to main content

Notifications

Announcements

No record found.

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 Microsoft Employee

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

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Filtering Subgrid using JavaScript and FetchXML

    Thanks Andrew, thought this might have been the case.

  • Aric Levin Profile Picture
    Aric Levin 30,188 on at
    RE: Filtering Subgrid using JavaScript and FetchXML

    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.

  • Verified answer
    a33ik Profile Picture
    a33ik 84,325 Most Valuable Professional on at
    RE: Filtering Subgrid using JavaScript and FetchXML

    Hello Katie,

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

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,489 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,305 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans