Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Programmatically filtering subgrid

(0) ShareShare
ReportReport
Posted on by

Hi,

I am trying to filter this subgrid ShipmentReportsInformation by the end customer field to show only the end customer records of the account that I'm currently viewing. Right now it's showing all of them (can't use the "show only related records" in the form because it's just text).

4401.Screenshot_5F00_1.png

So I made a web resource (onload event) and this is what I have put together so far:

function Filter(){

  var str = Xrm.Page.getAttribute('name').getValue(); //this contains the correct text
  //alert(str); 

  var AllRows = Xrm.Page.getControl("ShipmentReportsInformation").getGrid().getRows(); //all rows inserted in AllRows
  var FilteredRows = AllRows.forEach(function (AllRows, i) {
  if(Xrm.Page.getAttribute('new_endcustomer').getValue() == str){
    FilteredRows.push(AllRows.getData().getEntity().getEntityReference());
  }
//Now I think I should only have the lines added to the FilteredRows variable that match the if condition
  });
  
  Xrm.Page.getControl("ShipmentReportsInformation").setData(FilteredRows); //putting the data from the var in the subgrid

}

Sadly, it's not working and the log/error report I get isn't any help at all. The error:

Screenshot_5F00_58.png


Can anyone help me spot the issues in the code please? I don't have much expierence coding, any help is appreciated.

I even think it's loading the code before the subgrid is loaded but I don't know how to properly delay it. I tried .getreadystate != complete but it's never complete according to that.

I got most of my information from here:
https://msdn.microsoft.com/en-us/library/dn932126.aspx#BKMK_GridRowData and https://msdn.microsoft.com/en-us/library/dn932137.aspx If that helps any.

Kind regards

*This post is locked for comments

  • Verified answer
    Tim Dutcher Profile Picture
    Tim Dutcher 2,100 on at
    RE: Programmatically filtering subgrid

    According to the CRM SDK, the setData function that you're using only works with Silverlight web resources, so that's one issue with the code.

    Here's a related thread on this topic: https://community.dynamics.com/crm/f/117/t/201756

    The thread mentions the use of an unsupported function named SetParameter to set the FetchXml of a subgrid. You can try to use it but be aware that it might break at any time when CRM is updated.

    I suggest making End Customer a lookup so that you can use the out-of-box way of showing related records.

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

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

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,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,407 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans