Quantcast
Channel: Microsoft Dynamics CRM Forum - Recent Threads
Viewing all articles
Browse latest Browse all 46379

Programmatically filtering subgrid

$
0
0

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).

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:

 


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

Viewing all articles
Browse latest Browse all 46379

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>